Bash-意外的文件结尾

Bash-意外的文件结尾,bash,Bash,我一直在用bash脚本在程序上运行测试,但似乎找不到语法错误。当我使用-x时,它告诉我它期待一个},但我找不到它 请看下面的代码 #!/bin/bash usagearg() { echo "You're missing an argument on the command line!" >&2} usagemiss() { echo "A file requested in your filestem is missing or cannot be read!"

我一直在用bash脚本在程序上运行测试,但似乎找不到语法错误。当我使用-x时,它告诉我它期待一个},但我找不到它

请看下面的代码

#!/bin/bash
usagearg() {
    echo "You're missing an argument on the command line!" >&2}
usagemiss() {
    echo "A file requested in your filestem is missing or cannot be read!" >&2}
if [ ${#} -ne 2 ]; then
    usagearg;
    exit 1;
fi
x=1
endp=`wc -l ${1}`
end=$((endp+1))
while [ ${x} -ne ${end} ] ; do
    # redacted code which isn't related to the issue at hand.
done

我觉得我已经关闭了所有的循环和if,以及所有的括号,所以我不明白为什么会出现语法错误。

复合命令括号内的命令列表必须以分号或换行符终止;右大括号本身不够

任用

usagearg() {
    echo "You're missing an argument on the command line!" >&2; }

正如所写的,您的代码将右大括号视为另一个字符,并且是输出重定向的一部分,因为不存在中间空白



至于为什么需要这样做,您必须回到
bash
如何定义某些字符。有一组元字符,可以在不带引号的情况下分隔单词。还有一组控制运算符,模糊地定义为执行“控制功能”。右大括号
}
不属于这两个类别。(为什么?我不确定,但我认为这与在参数扩展中使用大括号(
${foo}
)有关,这使得它无法进行其他特殊处理。)

您可能需要关闭函数
usagemiss()
尝试将关闭大括号移动到usagerg()和usagemiss()函数中的新行。他们可能会被重定向吞没。在我看来,看起来也更好。
usagearg() {
    echo "You're missing an argument on the command line!" >&2
}