mardi 1 décembre 2015

syntax error using if in a bash script

I want to modify an existing bash script to avoid asking input data from the usedr if any parameter is passed. now the part if the existing script is as follow and works fine :

options=("a" "b" "c"  "d"  "e")
select opt in "${options[@]}"

I'm changing with this:

options=("a" "b"  "c"  "d")
if [ $# = 0 ] ; then
        select opt in "${options[@]}"
else
        opt=$1
fi

When i run it (with or without parameter) i get the following error

/usr/local/sbin/script.sh: line 486: syntax error near unexpected token `else'
/usr/local/sbin/script.sh: line 486: `else'

Line 486 is the line with my else statement Any idea of what I'm doing wrong?

Aucun commentaire:

Enregistrer un commentaire