Skip to the content.

09. August 2023 - verfasst von Oliver Gaida - Kategorien: ["linux", "bash"]

grep - use dash in a search string within grep

if i grep a multiline output for a string that contais -linux then i try use the following

$ printf '1-linux\n2-linux\n'
1-linux
2-linux
$ printf '1-linux\n2-linux\n'|grep -linux
# => error

this is because grep tries to interpret -linux as an option specific to grep. To shut off this behaviour just use -- or -e in front of you search-string:

$ printf '1-linux\n2-linux\n'|grep -- -linux
1-linux
2-linux
$ printf '1-linux\n2-linux\n'|grep -e -linux
1-linux
2-linux
HOME