Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何防止shell脚本被ack模式转义弄糊涂_Bash_Ack - Fatal编程技术网

Bash 如何防止shell脚本被ack模式转义弄糊涂

Bash 如何防止shell脚本被ack模式转义弄糊涂,bash,ack,Bash,Ack,我正在尝试使用ack(在Haskell文件中)搜索+|+ 我看着 但这没用 在Mac OS X 10.6上,我得到以下响应: $ ack -Q +|+ -bash: +: command not found Missing option after + ack: See ack --help, ack --help-types or ack --man for options $ ack \+\|\+ Unknown option: | ack: See ack --help, ack --h

我正在尝试使用ack(在Haskell文件中)搜索+|+

我看着 但这没用

在Mac OS X 10.6上,我得到以下响应:

$ ack -Q +|+
-bash: +: command not found
Missing option after +
ack: See ack --help, ack --help-types or ack --man for options

$ ack \+\|\+
Unknown option: |
ack: See ack --help, ack --help-types or ack --man for options

$ ack [+][|][+]
-bash: ][+]: command not found
ack: Invalid regex '[+][':
  Unmatched [ in regex; marked by <-- HERE in m/[+][ <-- HERE /

$ ack \Q+|+\E
-bash: +E: command not found
$ack-Q+|+
-bash:+:未找到命令
之后缺少选项+
ack:有关选项,请参见ack--help,ack--help类型或ack--man
$ack\+\|\+
未知选项:|
ack:有关选项,请参见ack--help,ack--help类型或ack--man
$ack[+][|][+]
-bash:][+]:未找到命令
确认:无效的正则表达式'[+][':

Unmatched[在正则表达式中;标记为这应按预期工作:

$ ack "\+\|\+"

(根据您的评论进行编辑以确保正确。未加引号的管道为“或”。

-Q
将引用搜索字符串中的所有内容

ack --haskell -Q '+|+'
哪一个比

ack --haskell "\+\|\+"

这里的问题是,您正在处理两个级别的转义,首先是
bash
,然后是
ack
本身。尝试在参数周围加上引号,让它们通过
bash
,然后应用链接问题中有关
ack
的提示。它为我运行,但它匹配+++,而我想精确匹配+++。我尝试过了逃避“使用”\+\\\\+“-这很有效-谢谢我刚刚意识到我上面引用的另一个问题中出现了引号-但不是答案-因此我错过了答案,直视着我的脸…感谢更正,我编辑了正确的答案,这样以后就不会让其他人混淆了。