Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am tryng to learn shell scripting, and i am still in the begining stages of
learning. I have a book that teaches unix, and it says that the correct
structure for an "if...then" statement is if elif else fi, but when i write my
script i always get a syntax error on "fi", "elif", and "else" i will include
my sample script, please tell me what am i doing wrong!if [ $# = 0 ] then
echo Error! Paramater requred.
exit 1
fi
if [ "$1" = "Dog" ] then
echo Bow Wow!
elif [ "$1" = "Cat" ] then
echo Meow!
else
echo Error!: Invalid Paramater
fi

I haven't done any scripting before and I need
to write the following script.The name of the script will be lab6
It will be invoked with a parameter of at least two digits. Example:
lab6 105
The date will be displayed on the screen.
The script will extract the last digit of the input parameter. This will be compared to the last digit of the current day of the month (E.g. Christmas is on day 25; use the 5). A message will then be displayed on the screen indicating if the digits are the same or not.
The script will request the user to enter a number between 1 and 10.
The script will display the number and its square on the screen

Answer to the first post:
You are missing semi-colons between the test and "then":if [ $# = 0 ]; then
echo Error! Paramater requred.
exit 1
fi
if [ "$1" = "Dog" ]; then
echo Bow Wow!
elif [ "$1" = "Cat" ]; then
echo Meow!
else
echo Error!: Invalid Paramater
fi
-jim

Also,
enclose your echo commands in double quotes, so the shell doesn't get them:if [ $# = 0 ]; then
echo "Error! Paramater requred."
exit 1
fi
if [ "$1" = "Dog" ]; then
echo "Bow Wow!"
elif [ "$1" = "Cat" ]; then
echo "Meow!"
else
echo "Error!: Invalid Paramater"
fi
-jim

Jim,
thank you so much, i can't believe i overlooked that! I feel really silly now that i realize what it was, and I appreciate your help very much.
Thanks Again,
Freedom

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |