bash 中的案例:"line 4: syntax error near unexpected token `)'"
case in bash: "line 4: syntax error near unexpected token `)'"
bash 中的案例:
line 4: syntax error near unexpected token `)'
我正在尝试在 Bash 中使用命令 case
(再次在我的 Raspberry Pi 上),但是当我 运行 我的脚本时,Bash吐出错误。我已经阅读了很多教程,我认为我正在做与他们相同的事情,但有些地方不对。
这是我的代码:
#!/bin/bash
case "" in
help) echo "You asked for help. Sorry, I'm busy."
*) echo "You didn't say anything. Try 'help' as the first argument."
esac
这是输出(文件名为 newmkdir,我 运行 它没有参数):
./newmkdir: line 4: syntax error near unexpected token `)'
./newmkdir: line 4: ` *) echo "You didn't say anything. Try 'help' as the first argument."'
我试图让我的脚本解释 help
,然后在下一行输出任何其他内容。
(注意这只是一个有问题的脚本的例子。这个脚本没有任何意义,甚至可能没有意义,它只是一个测试。)
您在每个模式的末尾缺少 ;;
:
#!/bin/bash
case "" in
help)
echo "You asked for help. Sorry, I'm busy."
;;
*)
echo "You didn't say anything. Try 'help' as the first argument."
;;
esac
将其视为编程语言中的 break
语句。它们在 case
.
是强制性的
bash 中的案例:
line 4: syntax error near unexpected token `)'
我正在尝试在 Bash 中使用命令 case
(再次在我的 Raspberry Pi 上),但是当我 运行 我的脚本时,Bash吐出错误。我已经阅读了很多教程,我认为我正在做与他们相同的事情,但有些地方不对。
这是我的代码:
#!/bin/bash
case "" in
help) echo "You asked for help. Sorry, I'm busy."
*) echo "You didn't say anything. Try 'help' as the first argument."
esac
这是输出(文件名为 newmkdir,我 运行 它没有参数):
./newmkdir: line 4: syntax error near unexpected token `)'
./newmkdir: line 4: ` *) echo "You didn't say anything. Try 'help' as the first argument."'
我试图让我的脚本解释 help
,然后在下一行输出任何其他内容。
(注意这只是一个有问题的脚本的例子。这个脚本没有任何意义,甚至可能没有意义,它只是一个测试。)
您在每个模式的末尾缺少 ;;
:
#!/bin/bash
case "" in
help)
echo "You asked for help. Sorry, I'm busy."
;;
*)
echo "You didn't say anything. Try 'help' as the first argument."
;;
esac
将其视为编程语言中的 break
语句。它们在 case
.