how to stop shell script from getting confused by ack PATTERN escapes

StackOverflow https://stackoverflow.com/questions/16211126

  •  11-04-2022
  •  | 
  •  

سؤال

I am trying to use ack to search (in Haskell files) for +|+

I looked at ack-grep: chars escaping but this doesn't help

On Mac OS X 10.6 I get the following responses:

$ 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

That's basically all the suggestions in the Q&A listed above

هل كانت مفيدة؟

المحلول

This should work as intended:

$ ack "\+\|\+"

(Edited to be correct per your comments. Unquoted pipe is 'or'.)

نصائح أخرى

The -Q will quote everything in your search string.

ack --haskell -Q '+|+'

which is easier than

ack --haskell "\+\|\+"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top