Search code examples
stringsearchescapingack

How do I search for the string '--branch' using ack?


In ack you can use the -Q option to escape all the characters in your search string, but that doesn't seem to work if the search string you are using looks like an option for ack.

I am trying to search a group of files for the string '--branch'. So I try this ack command

ack -a -Q '--branch'

It responds Unknown option: branch. It is seeing my search string as an option to be interpreted. Does anyone know what escape characters I can use to use the --branch as a string?


Solution

  • Ack uses the Getopt::Long module to process command line arguments, so it supports the -- option to indicate that you want option processing to end at that point in the argument list.

    ack -a -- --branch
    

    should therefore work (it does for me).