【问题标题】:Syntax error: word unexpected (expecting "in")语法错误:单词意外(期待“in”)
【发布时间】:2014-10-21 10:49:07
【问题描述】:

我正在编写脚本,但出现错误:语法错误:单词意外(预期“输入”) 我真的不知道错误可能在哪里

#!/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

【问题讨论】:

  • 你的脚本真的是这样的双倍行距吗?所有这些空行都不是特别有用。一致的缩进将是。
  • 您可能想阅读 bash 手册页中的 getopts 命令。

标签: bash


【解决方案1】:

正如错误所说,缺少“in”。每the case syntax

case word in [[(] pattern [| pattern]…) command-list ;;]… esac

但代码中 ($#) 后面没有“in” - 添加它。

【讨论】:

  • 更不用说$# 永远不会匹配-d-x
  • 在破坏性的mv 命令开始重新排列之前,可能首先要进行语法检查和不应该做的事情......
猜你喜欢
  • 2019-03-27
  • 2012-07-04
  • 2017-09-12
  • 1970-01-01
  • 2019-12-06
  • 2013-11-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多