Reputation: 79
I'm new to bash and I'm trying to write a script that will prompt the user to select a number, and open the corresponding file. Right now i just wanted to get the options to work properly but I get the error:
./filescript: line 7: syntax error near unexpected token `elif'
./filescript: line 7: `elif [[$server == 2]]'
Anytime I try to make a selection when it's ran. Here's what I have, any advice is appreciated!
#!/bin/bash
echo "Which file would you like to open: "
read input
if [[$input == 1]] then
echo "This is the first option"
elif [[$input == 2]]
echo "This is the second option"
else
echo "Error"
fi
Upvotes: 0
Views: 8315
Reputation: 367
There're syntax error in your code.
;
should addedthen
keyword in second elif
the correction will be
#!/bin/bash
echo "Which file would you like to open: "
read input
if [[ $input == 1 ]] ;then
echo "This is the first option"
elif [[ $input == 2 ]] ;then
echo "This is the second option"
else
echo "Error"
fi
See online version http://tpcg.io/8zfbh4
Upvotes: 1
Reputation: 12022
I typically do my IF statements like this for strings
if [ "$input" == "1" ]
or like this for numerical
if [ $input -eq 1 ]
EDIT: try putting a space after the [
and before the ]
$ if [[ $X == 1 ]] ; then echo "yes"; fi
yes
$ if [[$X == 1]] ; then echo "yes"; fi
bash: [[1: command not found
Upvotes: 1