【问题标题】:Bash on Ubuntu Server: find: missing argument to `-exec'Ubuntu 服务器上的 Bash:find:缺少 `-exec' 的参数
【发布时间】:2014-05-25 11:19:45
【问题描述】:

我有以下脚本,在 FreeNas 上运行良好。 现在,在 Ubuntu 上使用它会出现以下错误:

发现:`-exec' 缺少参数

#!/bin/bash

find /fileshare/Zund/export/ \
    -type f \
    ! -exec lsof -n "{}" \; \
    -exec cp "{}" /fileshare/Zund/zund1/ \; \
    -exec chmod -R 777 /fileshare/Zund/zund1/ \; \
    -exec cp "{}" /fileshare/Zund/zund2/ \; \
    -exec chmod -R 777 /fileshare/Zund/zund2/ \; \
    -exec rm "{}" \;.

非常感谢任何帮助:)

干杯

【问题讨论】:

  • 最后那个点是故意的吗?您是否已经尝试自己调试问题? (例如通过降低 find 命令的复杂性)对此有何见解?
  • 你可能也应该避开那个感叹号。

标签: linux bash ubuntu exec freebsd


【解决方案1】:

脚本末尾的点。

我认为,你的问题在这个点。例如以下命令给出了相同的错误
find ./ -type f -exec ls \;.。这里点的目的是什么?

来自find的人:

-执行命令;
执行命令;如果返回 0 状态,则为 true。以下所有要查找的参数都被视为命令的参数 直到一个由 `;' 组成的参数遇到。 ...

我认为,最后的那个点(而不是 ;)会中断对最后一个参数的解析,并且您
会收到错误消息。

【讨论】:

  • 谢谢 - 这是正确的答案。去掉末尾的点,即有“;”代替 ”;。”是解决方案。
【解决方案2】:

猜测:你的 FreeNas 盒子使用了一个更简单的外壳,它没有历史扩展功能。

因此,您不必在该 shell 上转义该感叹号,但您需要在 bash 上执行此操作。 - 否则它会将其解释为历史扩展。

bash 手册页说:

QUOTING
   Quoting  is used to remove the special meaning of certain characters or words
   to the shell.  Quoting can be used to disable special treatment  for  special
   characters,  to  prevent reserved words from being recognized as such, and to
   prevent parameter expansion.

   Each of the metacharacters listed above under DEFINITIONS has special meaning
   to the shell and must be quoted if it is to represent itself.

   When  the  command  history  expansion facilities are being used (see HISTORY
   EXPANSION below), the history expansion character, usually !, must be  quoted
   to prevent history expansion.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-05
    • 2020-10-10
    • 2011-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多