1
votes

I need to write a little bash program. Now i want to use the case function but i receive the error message

./arbeit1.sh: line 26: syntax error near unexpected token ;;' ./arbeit1.sh: line 26: auswertung();;'

read auswahl 
case "$auswahl" in
"1")
    echo "Sternbox";;
"2")
    auswertung();;
"3")
    array();;
"4")
    exit;;
*)
    echo "Falsche Eingabe - Probieren Sie es nochmal";;
esac
1
Don't use "()" to call a function. It is used to define a new function, and the body should follow, hence the syntax error. - meuh
In bash, functions are called in exactly the same way as any other command: it is not C/C++/Java/C# ! - cdarke

1 Answers

1
votes

Problem are the parenthesis in your function calls. That is not valid BASH code.

Try the following:

read auswahl
case $auswahl in
  "1")
    echo "Sternbox"
    ;;
  "2")
    auswertung     # note no () here!
    ;;
  "3")
    array
    ;;
  "4")
    exit 0
    ;;
  *)
    echo "Falsche Eingabe - Probieren Sie es nochmal"
esac