找到-exec ARG命令fusses [英] find command fusses on -exec arg

查看:245
本文介绍了找到-exec ARG命令fusses的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立和从脚本运行找到命令。但是,我从一个非常神秘的错误消息找到。下面基本上概括了我是如何构建命令行,并运行它。

I am trying to build and run a find command from a script. But I get a very cryptic error message from find. The following basically sums up how I build the command line and run it

$ xx="find . -name 'p*' -mmin +10 -exec echo {} \\;"
$ echo "$xx" #.....and I get the same print from echo $xx
find . -name 'p*' -mmin +10 -exec echo {} \;
$ $xx
find: missing argument to `-exec'
$ find . -name 'p*' -mmin +10 -exec echo {} \;
./p2.sh
./p1.sh
$ read xx
find . -name 'p*' -mmin +2 -exec echo {} \\;
$ $xx
find: missing argument to `-exec'

我坚持和意志AP preciate你的帮助。我也想知道是什么导致了这一点。我使用bash的SLES 51年2月​​3日。

I am stuck and will appreciate your help. I am also wondering what's causing this. I am using bash 3.2.51 on SLES.

实际的命令我想执行是一个有点长,但我用回声这里只是为了说明。

The actual command I want to execute is a little bit longer but I used echo here just to illustrate.

谢谢
迪内希

推荐答案

尝试存储在bash变量复杂的命令,然后评估的变量pretty也从不工作。

Trying to store complicated commands in bash variables and then evaluate the variables pretty well never works.

如果您需要建立枚命令,使用数组。看到这个有用的Bash的常见问题解答:我想在一个变量把一个命令,但复杂的案件总是失败!

If you need to build a command in pieces, use an array. See this useful Bash FAQ: I'm trying to put a command in a variable, but the complex cases always fail!.

下面是基本策略:

# Make an array
declare -a findcmd=(find .)
# Add some arguments
findcmd+=(-name 'p*')
findcmd+=(-mmin +10)
findcmd+=(-exec echo {} \;)
# Run the command
"${findcmd[@]}"

您需要了解的bash引用的作品。请记住,引用(和去报价)的只会发生一次的,当你键入命令(或庆典时,从脚本文件中读取它)。其中进入变量的值行情只是普通的字符。

You need to understand how bash quoting works. Remember that the quoting (and de-quoting) only happens once, when you type the command (or when bash reads it from a script file). Quotes which get into the values of variables are just ordinary characters.

如果你使用实验设置-x ,也是设置-x记得插入报价的以除去歧义。这些报价的不变量的一部分。虽然这显然是必不可少的,它似乎是混乱的程序员谁不熟悉bash的执行模型。

If you're experimenting with set -x, remember also that set -x inserts quotes in order to remove ambiguities. These quotes are not part of the variables. While that is clearly essential, it seems to be confusing to programmers who are not familiar with the bash execution model.

这篇关于找到-exec ARG命令fusses的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆