Guys, Im trying to have a script that evaluates multiple conditions :
test.sh:
if [ $1 = "brazil1" ]
then
echo "host $1"
else
if [ $1 = "brazil2" ]
then
echo "host $1"
else
echo $1 not valid
exit 1
fi
when I do
./test.sh brazil1
I get:
./test.sh: line 12: syntax error: unexpected end of file
I'm not sure what I'm doing wrong, could you give me a hand on it please?
Thanks
You have two 'if' and only one 'fi' if I saw this correctly. Use the code tag.
Im sorry for not using the code tag, I will next time
What I'm trying to do is to have a script where I can send one parameter and based on that parameter execute a function.
if the script received brazil1 then echo something, if it receives brazil2 then echo something else.. etc.. etc..
Thanks guys, I'm sorry for the dumb question but I cant figure it out..
I don't see you put in the second 'fi' yet at the end so I'll change the second else to 'elif' for you:
if [ $1 = "brazil1" ]; then
echo "host $1"
elif [ $1 = "brazil2" ]; then
echo "host $1"
else
echo $1 not valid
exit 1
fi
I'd rather use cases, e.g.:
case $1 in
"brazil1")
# do this
;;
"brazil2")
# do that
;;
*)
# oops ;-)
;;
esac
(background information)