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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 11:14:40  来源:igfitidea点击:

Syntax error: word unexpected (expecting "in")

bash

提问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” - 添加它。