【发布时间】:2011-12-05 12:03:33
【问题描述】:
我在使用 ack-grep 时遇到了问题。
我正在运行这个命令:
ack-grep "paypal_responded(?!_at)"
但我收到了错误:
bash: !_at: event not found
我尝试在不同的地方添加反斜杠,但我对使用 ack 和 linux 也很陌生,所以请把我当作新手,有任何说明。
提前致谢。
【问题讨论】:
标签: linux command-line ack
我在使用 ack-grep 时遇到了问题。
我正在运行这个命令:
ack-grep "paypal_responded(?!_at)"
但我收到了错误:
bash: !_at: event not found
我尝试在不同的地方添加反斜杠,但我对使用 ack 和 linux 也很陌生,所以请把我当作新手,有任何说明。
提前致谢。
【问题讨论】:
标签: linux command-line ack
试试ack-grep 'paypal_responded(?!_at)'
您需要单引号以避免 bash 将 ! 解释为历史扩展命令。
【讨论】:
( ) 和! 更实用
shell 将您输入中的 ! 解释为命令替换:
$ ack-grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
$ !ac
ack-grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
$
你需要告诉shell!没有特殊含义;有两种方法可以做到这一点:
罢工>
ack-grep "paypal_responded(?\!_at)"
ack-grep "paypal_responded\(?\!_at\)"
或
ack-grep 'paypal_responded(?!_at)'
单引号字符串应用的转换较少:
$ ack-grep "s\!" /etc/passwd
$ ack-grep 's!' /etc/passwd
$
【讨论】:
(?!_at) 的较长示例以可怕的方式失败了,很容易看出你为什么要开车你自己疯了,试图让它发挥作用。 ack-grep "paypal_responded\(?\!_at\)" 工作正常....但我无法解释。