bash 中意外标记“elif”附近的语法错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8342537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Syntax error near unexpected token "elif" in bash
提问by t3hcakeman
Here's my code to display some dialogs.
这是我显示一些对话框的代码。
#!/bin/bash
output=$(zenity --list --text="Choose action" --column= --hide-header "Hidden Files" "Desktop")
if [ $output = "Hidden Files"]
then
output2=$(zenity --list --text="Do what?" --column= --hide-header "Show" "Hide")
if [ $output2 = "Show"]
then
echo showing files
else
echo hiding files
elif [ $output = "Desktop"];then
output3=$(zenity --list --text="Do what?" --column= --hide-header "Show" "Hide")
if [ $output2 = "Show"]
then
echo showing files
else
echo hiding files
else
exit
fi
I get this error after the first dialog:
第一次对话后我收到此错误:
systool.sh: line 12: syntax error near unexpected token `elif'
systool.sh: line 12: `elif [ $output = "Desktop"];then'
Whats wrong?
怎么了?
回答by dogbane
You need to close both of your inner if-else statements with a fi.
您需要使用fi.
For example:
例如:
if [ $output2 = "Show"]
then
echo showing files
else
echo hiding files
fi
You also need a space before the closing ]in your if conditions. For example:
您还需要]在 if 条件中的结束之前留一个空格。例如:
if [ $output2 = "Show" ]
回答by Aaron Digulla
You're missing a fiafter both echo hiding files
你错过了fi两个echo hiding files
回答by Michael Krelin - hacker
Your inner ifs have no corresponding fis.
您的内部ifs 没有相应的fis。

