【问题标题】:Bash with case syntax error `;;'带有大小写语法错误的 Bash `;;'
【发布时间】:2017-07-31 08:54:16
【问题描述】:

我需要编写一个小 bash 程序。现在我想使用 case 函数但我收到错误消息

./arbeit1.sh:第 26 行:意外标记附近的语法错误 ;;' ./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

【问题讨论】:

  • 不要使用“()”来调用函数。它用于定义一个新函数,并且主体应该跟随,因此语法错误。
  • 在 bash 中,函数的调用方式与任何其他命令完全相同:它不是 C/C++/Java/C#!

标签: bash case


【解决方案1】:

问题是函数调用中的括号。这不是有效的 BASH 代码。

尝试以下方法:

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

【讨论】:

    猜你喜欢
    • 2023-01-06
    • 1970-01-01
    • 1970-01-01
    • 2022-07-02
    • 1970-01-01
    • 2016-11-09
    • 2017-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多