在Ubuntu服务器上进行Bash:找到:缺少`-exec'的参数

时间:2014-05-25 11:19:45

标签: linux bash ubuntu exec freebsd

我有以下脚本,在FreeNas上运行得非常好。 现在,在Ubuntu上使用它有以下错误:

find:缺少`-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 "{}" \;.

非常感谢任何帮助:)

干杯

2 个答案:

答案 0 :(得分:0)

狂野猜测:你的FreeNas框使用了一个更简单的shell,它没有历史扩展功能。

因此,您不必在该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.

答案 1 :(得分:0)

脚本末尾的点。

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

来自find的男人:

  

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

我假设,最后一个点(而不是;)会中断最后一个参数的解析,然后你会收到错误信息。

相关问题