Shell Scripting Problem

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2008
Posts: 1
Reputation: a.kris is an unknown quantity at this point 
Solved Threads: 0
a.kris a.kris is offline Offline
Newbie Poster

Shell Scripting Problem

 
0
  #1
Aug 28th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 10
Reputation: sparty is an unknown quantity at this point 
Solved Threads: 0
sparty sparty is offline Offline
Newbie Poster

Re: Shell Scripting Problem

 
0
  #2
Aug 28th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: Shell Scripting Problem

 
0
  #3
Aug 28th, 2008
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
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,035
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Shell Scripting Problem

 
0
  #4
Aug 28th, 2008
Last edited by Aia; Aug 29th, 2008 at 12:00 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: Shell Scripting Problem

 
0
  #5
Aug 30th, 2008
Good point. Totally looked right past that. There are spaces to the left and right of all the assignment (=) operators... WOW

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,035
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Shell Scripting Problem

 
0
  #6
Aug 30th, 2008
Originally Posted by eggi View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: Shell Scripting Problem

 
1
  #7
Aug 31st, 2008
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
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC