寻找匹配的')'时出现意外的EOF错误 [英] Unexpected EOF error while looking for matching `)'
问题描述
尝试运行bash脚本并且某些功能正常运行时,我收到以下消息:
Trying to run a bash script and while some things work correctly, I get this message:
line 34: unexpected EOF while looking for matching `)'
这是代码,我在斜边方法中标记了有问题的行:
Here's the code, I've marked the line in question (in the hypotenuse method):
#!/bin/bash
# Bash Script Calculator
# -----------------------------------------------------
#
#
#
# -----------------------------------------------------
a=$1
op="$2"
b=$3
if [ $# -lt 3 ]
then
echo "$0 num1 opr num2"
echo "Operators: +,-,x,/"
exit 1
fi
case "$op" in
+) echo $(( $a + $b ));;
-) echo $(( $a - $b ));;
x) echo $(( $a * $b ));;
/) echo $(( $a / $b ));;
hyp) hypotenuse;;
area) area;;
*) echo "Error: Not a listed operator"
echo "If using multiplication, use "x"";;
esac
hypotenuse()
{
hyp=$(bc -l << EOF #LINE 34
scale = 9
sqrt ( $1 * $1 + $3 * $3 )
EOF
)
echo "$hyp"
}
area()
{
area=$(echo "scale=2;3.14 * ($a * $a)" | bc)
echo "$area"
}
我错过了什么吗?我花了一些时间在Google上查找内容,否则,似乎没有什么可以告诉我的.
Am I missing something? I've spent a little time looking things up on Google and such, nothing seems to tell me otherwise.
感谢您的帮助!
推荐答案
您的heredoc终结符错误:
Your heredoc terminator is wrong:
{
hyp=$(bc -l << EOF #LINE 34
scale = 9
sqrt ( $1 * $1 + $3 * $3 )
EOF
^^^^---these spaces count
您的终止符现在实际上是[space][space][space][space]EOF
,而bash正在寻找EOF
,而没有空格.终止符必须从行的开头开始,在行的前面(或后面)没有空格.
Your terminator is now actually [space][space][space][space]EOF
, while bash is looking for EOF
WITHOUT the spaces. The terminator MUST begin at the start of the line, without any whitespace before (or after) it.
由于您的Heredoc永远不会终止,因此bash会在脚本的结尾处运行,以寻找一个永远不会出现的)
,因为Heredoc消耗了您实际拥有的那个.
Since your heredoc never terminates, bash will run right off the end of the script looking for a )
which never comes, because the heredoc consumed the one you actually did have.
这篇关于寻找匹配的')'时出现意外的EOF错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!