0

Why is this script giving an "Unexpected end of file" syntax error in the last line?

{ [ $# -ne 2 ] && [ $# -ne 3 ] } && { echo "Uso: $0 [opciones] [nlineasresultado] [archivos a analizar]" && echo "NEED 2 OR 3 PARAMETERS" && exit 1 }
echo sucessfull
exit 0
3

See the bash man page, which shows that the syntax when using braces ({, }) is:

{ list; }

This means that you are missing a couple of semicolons:

{ [ $# -ne 2 ] && [ $# -ne 3 ]; } && { echo "Uso: $0 [opciones] [nlineasresultado] [archivos a analizar]" && echo "NEED 2 OR 3 PARAMETERS" && exit 1; }

Note that you can also use newlines to achieve the same thing. That is, this is an error:

{ echo hello }

But this works:

{ echo hello; }

As does this:

{
echo hello
}
1

bash command grouping, {}, needs a ; before the closing brace ,}, as you didn't have put it hence the error.

Do:

{ [ $# -ne 2 ] && [ $# -ne 3 ] ;} && { echo "Uso: $0 [opciones] [nlineasresultado] \
          [archivos a analizar]" && echo "NEED 2 OR 3 PARAMETERS" && exit 1 ;}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.