Computing.Net > Forums > Unix > Korn Shell Scripting

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Korn Shell Scripting

Reply to Message Icon

Name: freedom
Date: November 2, 2002 at 15:29:17 Pacific
OS: UNIX
CPU/Ram: Old DEC unix machine at B
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Andrey
Date: November 2, 2002 at 18:31:46 Pacific
Reply:

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


0

Response Number 2
Name: jimbo
Date: November 2, 2002 at 19:19:44 Pacific
Reply:

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


0

Response Number 3
Name: jimbo
Date: November 2, 2002 at 19:22:33 Pacific
Reply:

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


0

Response Number 4
Name: freedom
Date: November 2, 2002 at 19:35:05 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Korn Shell Scripting

Korn shell script doubt ??? www.computing.net/answers/unix/korn-shell-script-doubt-/3407.html

sftp Korn shell script www.computing.net/answers/unix/sftp-korn-shell-script/4741.html

Korn Shell script for julian date? www.computing.net/answers/unix/korn-shell-script-for-julian-date/3729.html