bash 语法错误:单词意外(期望“in”)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25534145/
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: word unexpected (expecting "in")
提问by user3742475
i'm writing a script but get the error : Syntax error: word unexpected (expecting "in") I don't really see where the error could be
我正在编写一个脚本,但出现错误:语法错误:单词意外(期待“in”)我真的不知道错误可能在哪里
#!/bin/bash
for dir in "$@"
do
mv "$dir"/* /tmp
done
if [ $# -lt 1 ] ; then
echo "ERROR: no argument"
exit 1 # pas 0
else
case $#
-d) mv -R $dir/* /tmp
;;
-x) find -executable -type f | xargs mv -t "$dir"/* /tmp
;;
esac
fi
回答by user2864740
As the error says, "in" is missing. Per the case syntax,
正如错误所说,缺少“in”。根据case 语法,
case word in[ [(] pattern [| pattern]…) command-list ;;]… esac
字的情况下在[[(]图案[|图案] ...)命令列表;;] ... ESAC
but there is no "in" after the word ($#
) in the code - add it.
但是$#
代码中的( )之后没有“in” - 添加它。