943,597 Members | Top Members by Rank

Ad:
Aug 28th, 2008
0

Shell Scripting Problem

Expand Post »
Hey guys ..

I am pretty new to Shell Scripting. I was hoping if some one could help me out with my problem.

I am going with a tutorial for shell scripting. While executing some of the programs and commands I am getting errors. I have also checked other sites and tutorials for the same, but everything seems intact.
Following is the code. When I execute this (after changing the permission - 755), I get an error saying "unexpected end of file", Now I am not sure why this is happening ... please help me out.

Thanks in advance

Regards,
A Kris
Shell Scripting Syntax (Toggle Plain Text)
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2.  
  3. help_uni()
  4. {
  5. echo "Usage: $0 -n -a -s -w -d"
  6. echo "Option: These are optional argument"
  7. echo " -n name of animal"
  8. echo " -a age of animal"
  9. echo " -s sex of animal"
  10. echo " -w weight of animal"
  11. echo " -d demo values (if any of the above options are used"
  12. echo " their values are not taken)"
  13. exit 1
  14. }
  15.  
  16. if [ $# -it 10];then`
  17. help_ani
  18. fi
  19.  
  20. while getopts n:a:s:W:d opt
  21.  
  22. do
  23. case "$opt" in
  24. n) na ="$OPTARG";;
  25. a) age ="$OPTARG";;
  26. s) sex ="OPTARG";;
  27. w) weight ="$OPTARG";;
  28. d) isdef = 1;;
  29. \?) help_ani;;
  30. esac
  31. done
  32. if[ $isdef -eq 0];then`
  33. echo "Animal Name is $na, age is $age, sex is $sex, weight is $weight (user defined mode)"
  34. else''
  35. na = "pluto dog"
  36. age = 3
  37. sex = male
  38. weight = 20kg
  39. echo "Animal name is $na, age is $age, sex is $sex, weight is $weight (demo mode)"
  40. exit 1
  41. fi''
  42.  
  43. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Last edited by John A; Aug 28th, 2008 at 9:14 pm. Reason: added code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
a.kris is offline Offline
1 posts
since Aug 2008
Aug 28th, 2008
0

Re: Shell Scripting Problem

Im guessing it's because on your last line of the program you have an extra " after fi.
Last edited by sparty; Aug 28th, 2008 at 7:54 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sparty is offline Offline
10 posts
since Aug 2008
Aug 28th, 2008
0

Re: Shell Scripting Problem

There also seem to be a number of unnecessary backtick characters after a few then and else statements. That could be causing it.

Best wishes,

Mike
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007
Aug 28th, 2008
0

Re: Shell Scripting Problem

Last edited by Aia; Aug 29th, 2008 at 12:00 am.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Aug 30th, 2008
0

Re: Shell Scripting Problem

Good point. Totally looked right past that. There are spaces to the left and right of all the assignment (=) operators... WOW

, Mike
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007
Aug 30th, 2008
0

Re: Shell Scripting Problem

Click to Expand / Collapse  Quote originally posted by eggi ...
Good point. Totally looked right past that. There are spaces to the left and right of all the assignment (=) operators... WOW
, Mike
If it only were that ...

if [ $# -it 10];then`
#                   ^Wrong ` there
#             ^Need extra space there
#           ^Probably 1 (one) and not 10
#        ^-lt, not -it. Stands for `is less than'    
# corrected would be:
# if [ $# -lt 1 ]; then
# meaning: if not arguments where entered show menu
Spaces in the if statement between if and [ ] are important. They need to be respected.
With that in mind I leave if[ $isdef -eq 0];then` for you to figure what's wrong with it.
echo "Animal name is $na, age is $age, sex is $sex, weight is $weight (demo mode)"
exit 1 # Not need it
fi'' # Not need it
Before using the demo mode, those variables need to have something assigned to them since the user hasn't assigned anything.
Last edited by Aia; Aug 30th, 2008 at 11:46 pm.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Aug 31st, 2008
1

Re: Shell Scripting Problem

Guess I got mislead by the error message.. I'm surprised a script with so many errors didn't generate a much different one other than unexpected EOF
,Mike
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: copying corresponding language files
Next Thread in Shell Scripting Forum Timeline: Date comparing in Unix shell script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC