[英]Bash Syntax Error syntax error: unexpected end of file
我们正在使用Bourne-Again Shell。
这个错误是什么意思?:
syntax error: unexpected end of file
PS3="Press 1, 2, 3, 4 to do the thing they say next to them."
options=("Option 1" "Option 2" "Option 3" "Quit")
select opt in "${options[@]}"
do
case $opt in
"start game")
echo ok
;;
"level select")
echo "no"
;;
"how do i exit")
echo "click the window to close"
xkill
;;
"exit")
echo wwaaaatttt
echo click the window to kill it.
xkill
echo "if your reading this, you must have opened
echo "a game file. you've bricked the exit
echo button. great job.
;;
*) echo not a thing, sorry;;
esac
done
以单引号开头的字符串
ve bricked the
缺少右引号。 SO的语法突出显示了它。
也许您想反斜杠报价?
echo "a game file. you\'ve bricked the exit
还是也缺少双引号?
echo "if you're reading this, you must have opened"
echo "a game file. you've bricked the exit"
echo "button. great job."
在这种情况下,您也可以使用HERE-doc:
cat << 'EOF'
if you're reading this, you must have opened
a game file. you've bricked the exit
button. great job.
EOF
ShellCheck很有帮助:
Line 20:
echo "if your reading this, you must have opened
^-- SC1078: Did you forget to close this double quoted string?
确实,您做到了。 也在下一行。
这是没有语法错误的脚本(但是您仍然必须修复访问它们的选项):
PS3="Press 1, 2, 3, 4 to do the thing they say next to them."
options=("Option 1" "Option 2" "Option 3" "Quit")
select opt in "${options[@]}"
do
case $opt in
"start game")
echo ok
;;
"level select")
echo "no"
;;
"how do i exit")
echo "click the window to close"
xkill
;;
"exit")
echo wwaaaatttt
echo click the window to kill it.
xkill
echo "if your reading this, you must have opened" # HERE
echo "a game file. you've bricked the exit" # HERE
echo button. great job.
;;
*) echo not a thing, sorry;;
esac
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.