-   Linux - Newbie (
-   -   command --help | grep won't work (

vincix 11-17-2016 11:41 AM

command --help | grep won't work
Why doesn't wget --help | grep '-q' work? It's obviously interpreting the dash in a weird way, but I don't understand why it can't interpret it literally. Does it interpret it as stdout? Fgrep or grep -F doesn't work either.

michaelk 11-17-2016 11:49 AM

See below. Much better answer.

Turbocapitalist 11-17-2016 11:49 AM

You've got "grep" treating the -q as if it were an option for "grep" rather than a search term. You need to signal to "grep" that you have no more options and that the subsequent text should be treated as a search term. Adding a double dash -- will tell "grep" that there are no more options to follow.


wget --help | grep -- '-q'
Many programs need that double dash when working with patterns or text that start with a dash.

schneidz 11-17-2016 11:50 AM

the output of wget --help is probably going to stderr (not stdout). maybe you can redirect the wget output to stdout ?

actually, it worx for me:

[schneidz@hyper ~]$ wget --version
GNU Wget 1.18 built on linux-gnu.

-cares +digest -gpgme +https +ipv6 +iri +large-file +metalink +nls
+ntlm +opie +psl +ssl/openssl

    /etc/wgetrc (system)
    gcc -DHAVE_CONFIG_H -DSYSTEM_WGETRC="/etc/wgetrc"
    -DLOCALEDIR="/usr/share/locale" -I. -I../lib -I../lib -DHAVE_LIBSSL
    -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security
    -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong
    --param=ssp-buffer-size=4 -grecord-gcc-switches
    -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic
    gcc -DHAVE_LIBSSL -DNDEBUG -O2 -g -pipe -Wall
    -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions
    -fstack-protector-strong --param=ssp-buffer-size=4
    -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic
    -Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -lpcre
    -luuid -lmetalink -lssl -lcrypto -lz -lpsl -lidn ftp-opie.o
    openssl.o http-ntlm.o ../lib/libgnu.a

Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Originally written by Hrvoje Niksic <>.
Please send bug reports and questions to <>.
[schneidz@hyper ~]$ wget --help | grep relative
                                    relative to URL
  -L,  --relative                  follow relative links only

BW-userx 11-17-2016 12:29 PM


userx@voided1.what~>> wget --help | grep "\-q"
  -q,  --quiet                    quiet (no output)
  -Q,  --quota=NUMBER              set retrieval quota to NUMBER

userx@voided1.what~>> wget --help | grep 'q'
  -q,  --quiet                    quiet (no output)
  -nv, --no-verbose                turn off verboseness, without being quiet
                                    requests in timestamping mode
  -Q,  --quota=NUMBER              set retrieval quota to NUMBER
      --referer=URL              include 'Referer: URL' header in HTTP request
      --method=HTTPMethod        use method "HTTPMethod" in the request
      --warc-file=FILENAME        save request/response data to a .warc.gz file
  -p,  --page-requisites          get all images, etc. needed to display HTML page

michaelk 11-17-2016 12:48 PM

Thanks, noticed after I posted. Previous post corrected.

keefaz 11-17-2016 12:49 PM


wget --help | grep '^ *-q'
Or if you want to know about -Q as well

wget --help | grep -i '^ *-q'

vincix 11-17-2016 01:12 PM

Thank you all for your answers. I realised now that I actually tried to escape the dash, but I actually used a slash instead of a backslash, and that's why I thought that it doesn't work even with the escape character. But you need to quote or double quote in any case, it doesn't work simply by writing -q.

@schneidz I was thinking of stdrr too and was thinking of redirecting it to a file and the grep-ing it - but that's not so much fun.

Anyway, I learnt about the double dash option :)

All times are GMT -5. The time now is 09:27 AM.