# In appreciation of bare (naked) double-D(ashes)

Today I was trying to grep through a directory structure full of PHP code, looking for a function which, inexplicably, returned -6.

Grepping for anything with a dash as not as easy as one would think, since grep assumes the - indicates a command argument, and just pauses, waiting for further input, like this:

[davidy:~/tmp] 130 % grep -6 stupid-php-files/*
^C
[davidy:~/tmp] 130 % grep "-6" stupid-php-files/*
^C


No problem, I figured, I’ll just escape the dash. But nope, no, and na-da:

[davidy:~/tmp] 130 % grep \-6 stupid-php-files/*
^C


### Bare double dash does do the deed!

Finally, Google leads me on a journey of discovery of “bare double dashes”.

It turns out, a double-dash (--) indicates to the built-in bash commands that we’re done with command options, allowing the -6 to be searched for as a plain string:

[davidy:~/tmp] 130 % grep -- -6 stupid-php-files/*
return(-6); # because stupid
[davidy:~/tmp] %


### What about brackets?

What about grepping for open/closing brackets? (hi, @tjh)

Turns out that is just as simple as escaping the bracket, as illustrated below:

[davidy:~/tmp] % grep (because stupid-php-files/*
zsh: unknown file attribute: b
[davidy:~/tmp] 1 % grep \(because stupid-php-files/*
(because I can)
[davidy:~/tmp] %


### Practical test 🐒

When I shared my new, groundbreaking discovery, one of my colleagues pointed out that the following is therefore completely safe (while at the same time quite terrifying):

rf -- -rf /


To prove it (yes, I tested on stupid-php-files first!):

[davidy:~/tmp] 1 % rm -- -rf /
rm: -rf: No such file or directory
rm: /: is a directory
[davidy:~/tmp] 1 %
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.5840293765068054, "perplexity": 14677.362144319573}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-35/segments/1566027317037.24/warc/CC-MAIN-20190822084513-20190822110513-00060.warc.gz"}