LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-17-2016, 11:41 AM   #1
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
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.
 
Old 11-17-2016, 11:49 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
See below. Much better answer.

Last edited by michaelk; 11-17-2016 at 12:48 PM.
 
Old 11-17-2016, 11:49 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
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.

Code:
wget --help | grep -- '-q'
Many programs need that double dash when working with patterns or text that start with a dash.
 
2 members found this post helpful.
Old 11-17-2016, 11:50 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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:
Code:
[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 

Wgetrc: 
    /etc/wgetrc (system)
Locale: 
    /usr/share/locale 
Compile: 
    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 
Link: 
    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 
    -grecord-gcc-switches 
    -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
<http://www.gnu.org/licenses/gpl.html>.
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 <hniksic@xemacs.org>.
Please send bug reports and questions to <bug-wget@gnu.org>.
[schneidz@hyper ~]$ wget --help | grep relative
                                     relative to URL
  -L,  --relative                  follow relative links only

Last edited by schneidz; 11-17-2016 at 11:54 AM. Reason: ignore... misunderstood the question
 
Old 11-17-2016, 12:29 PM   #5
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Code:
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
 
Old 11-17-2016, 12:48 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
Thanks, noticed after I posted. Previous post corrected.
 
Old 11-17-2016, 12:49 PM   #7
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Code:
wget --help | grep '^ *-q'
Or if you want to know about -Q as well
Code:
wget --help | grep -i '^ *-q'
 
Old 11-17-2016, 01:12 PM   #8
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
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

Last edited by vincix; 11-17-2016 at 01:16 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why won't grep work on my logs? Rob00 Linux - Newbie 11 11-04-2009 06:16 PM
wall command won't work WilliamS Slackware 1 02-22-2007 11:54 PM
Iptables command won't work no_names_left Linux - Networking 9 04-23-2005 07:53 PM
rename command won't work Red Squirrel Linux - Newbie 4 03-03-2004 08:53 PM
rpm command won't work Travis86 Linux - Newbie 11 01-02-2003 05:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration