Hew*_*ess 2 linux bash case syntax-error
bash案例:
第4行:意外令牌附近的语法错误`)'
我正在尝试case在Bash中使用该命令(再次在我的Raspberry Pi上),但是当我运行我的脚本时,Bash会发出错误.我已经阅读了很多教程,我认为我做的与他们一样,但有些事情是不对的.
这是我的代码:
#!/bin/bash
case "$1" in
help) echo "You asked for help. Sorry, I'm busy."
*) echo "You didn't say anything. Try 'help' as the first argument."
esac
Run Code Online (Sandbox Code Playgroud)
这是输出(文件名是newmkdir,我运行它没有参数):
./newmkdir: line 4: syntax error near unexpected token `)'
./newmkdir: line 4: ` *) echo "You didn't say anything. Try 'help' as the first argument."'
Run Code Online (Sandbox Code Playgroud)
我正在尝试让我的脚本解释help,然后在下一行输出任何其他内容.
(注意这只是一个glitched脚本的例子.这个脚本没有任何意义,甚至可能没有意义,它只是一个测试.)
您;;在每个模式的末尾都缺少:
#!/bin/bash
case "$1" in
help)
echo "You asked for help. Sorry, I'm busy."
;;
*)
echo "You didn't say anything. Try 'help' as the first argument."
;;
esac
Run Code Online (Sandbox Code Playgroud)
将其视为break编程语言中的陈述.他们是强制性的case.
| 归档时间: |
|
| 查看次数: |
6833 次 |
| 最近记录: |