Ack & negative lookahead giving errors

2019-04-20 21:05发布

I have a problem with using ack-grep with a negative look ahead.

I am running this command:

ack-grep "paypal_responded(?!_at)"

but I am getting the error:

bash: !_at: event not found

I have tried adding backslashes in various places, but I'm also new to using ack & linux, so please treat me as a newbie with any instructions.

Thanks in advance.

2条回答
孤傲高冷的网名
2楼-- · 2019-04-20 21:29

The shell is interpreting the ! in your input as a command substitution:

$ 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
$ 

You need to tell the shell that ! has no special meaning; there are two ways to do that:

ack-grep "paypal_responded(?\!_at)"

ack-grep "paypal_responded\(?\!_at\)"

or

ack-grep 'paypal_responded(?!_at)'

Single-quoted strings have fewer transformations applied to them:

$ ack-grep "s\!" /etc/passwd
$ ack-grep 's!' /etc/passwd
$ 
查看更多
我想做一个坏孩纸
3楼-- · 2019-04-20 21:42

Try ack-grep 'paypal_responded(?!_at)'

You need single-quote to avoid bash interpret ! as history expand command.

查看更多
登录 后发表回答