Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #199429 > unrolled thread

sometimes i go huh (grep result)

Started bysongbird <songbird@anthive.com>
First post2018-08-27 17:20 +0200
Last post2018-08-27 20:10 +0200
Articles 6 — 5 participants

Back to article view | Back to linux.debian.user


Contents

  sometimes i go huh (grep result) songbird <songbird@anthive.com> - 2018-08-27 17:20 +0200
    Re: sometimes i go huh (grep result) Greg Wooledge <wooledg@eeg.ccf.org> - 2018-08-27 17:30 +0200
      Re: sometimes i go huh (grep result) Roberto C. Sánchez <roberto@debian.org> - 2018-08-27 18:20 +0200
    Re: sometimes i go huh (grep result) Roberto C. Sánchez <roberto@debian.org> - 2018-08-27 17:30 +0200
    Re: sometimes i go huh (grep result) Nicolas George <george@nsup.org> - 2018-08-27 17:30 +0200
    Re: sometimes i go huh (grep result) Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2018-08-27 20:10 +0200

#199429 — sometimes i go huh (grep result)

Fromsongbird <songbird@anthive.com>
Date2018-08-27 17:20 +0200
Subjectsometimes i go huh (grep result)
Message-ID<wrrt7-8e8-9@gated-at.bofh.it>
me@ant(25)$ env | grep -F "-g"
grep: invalid option -- 'g'
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
me@ant(26)$ env | grep -F '-g'
grep: invalid option -- 'g'
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
me@ant(27)$ env | grep -F 'CFL'
CFLAGS=-g
me@ant(28)$ env | grep '\-g'
CFLAGS=-g
me@ant(29)$ env | grep '-g'
grep: invalid option -- 'g'
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
me@ant(30)$ env | grep "-g"
grep: invalid option -- 'g'
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.


songbird

[toc] | [next] | [standalone]


#199430

FromGreg Wooledge <wooledg@eeg.ccf.org>
Date2018-08-27 17:30 +0200
Message-ID<wrrCO-8hh-3@gated-at.bofh.it>
In reply to#199429
On Mon, Aug 27, 2018 at 11:20:42AM -0400, Roberto C. Sánchez wrote:
> env |grep [-]g

Fails if there is a file named -g in the current directory, as that
matches the unquoted glob and causes it to expand.  Also fails if failglob
is turned on, whether the file exists or not (fails differently in the
two cases).

Also fails if nullglob is turned on, but that is definitely not
recommended in interactive shells.

[toc] | [prev] | [next] | [standalone]


#199442

FromRoberto C. Sánchez <roberto@debian.org>
Date2018-08-27 18:20 +0200
Message-ID<wrspc-l0-27@gated-at.bofh.it>
In reply to#199430
On Mon, Aug 27, 2018 at 11:26:12AM -0400, Greg Wooledge wrote:
> On Mon, Aug 27, 2018 at 11:20:42AM -0400, Roberto C. Sánchez wrote:
> > env |grep [-]g
> 
> Fails if there is a file named -g in the current directory, as that
> matches the unquoted glob and causes it to expand.  Also fails if failglob
> is turned on, whether the file exists or not (fails differently in the
> two cases).
> 
> Also fails if nullglob is turned on, but that is definitely not
> recommended in interactive shells.
> 
Quite right.  In my haste I forgot the quotes:

env |grep '[-]g'

-- 
Roberto C. Sánchez

[toc] | [prev] | [next] | [standalone]


#199432

FromRoberto C. Sánchez <roberto@debian.org>
Date2018-08-27 17:30 +0200
Message-ID<wrrCO-8hh-5@gated-at.bofh.it>
In reply to#199429
On Mon, Aug 27, 2018 at 10:36:12AM -0400, songbird wrote:
> me@ant(25)$ env | grep -F "-g"
> grep: invalid option -- 'g'
> Usage: grep [OPTION]... PATTERN [FILE]...
> Try 'grep --help' for more information.
> me@ant(26)$ env | grep -F '-g'
> grep: invalid option -- 'g'
> Usage: grep [OPTION]... PATTERN [FILE]...
> Try 'grep --help' for more information.
> me@ant(27)$ env | grep -F 'CFL'
> CFLAGS=-g
> me@ant(28)$ env | grep '\-g'
> CFLAGS=-g
> me@ant(29)$ env | grep '-g'
> grep: invalid option -- 'g'
> Usage: grep [OPTION]... PATTERN [FILE]...
> Try 'grep --help' for more information.
> me@ant(30)$ env | grep "-g"
> grep: invalid option -- 'g'
> Usage: grep [OPTION]... PATTERN [FILE]...
> Try 'grep --help' for more information.
> 
> 
try this:

env |grep [-]g

Regards,

-Roberto

-- 
Roberto C. Sánchez

[toc] | [prev] | [next] | [standalone]


#199433

FromNicolas George <george@nsup.org>
Date2018-08-27 17:30 +0200
Message-ID<wrrCO-8hh-21@gated-at.bofh.it>
In reply to#199429

[Multipart message — attachments visible in raw view] — view raw

songbird (2018-08-27):
> me@ant(25)$ env | grep -F "-g"
> grep: invalid option -- 'g'

Maybe what you want is an explanation rather than just a solution.

Quotes are for the shell: they protect arguments that contain special
characters, so that commands get them as is.

For example, you need to write:

	echo "Fire*Wolf"

because without the quotes, the shell would try to find all the files in
the current directory with a name that matches the pattern.

Since the dash is not special for the shell, the quotes are unnecessary.
They do no harm, but have no consequences here:

	grep "-g"
	grep '-g'
	grep -g
	grep ""''""-"g"''

all invoke grep with one extra argument "-g".

The dash is special for programs that understand options (some do not;
some do with a different syntax, for example key=value), and need to be
escaped the way programs expect it. The usual escaping is that an
argument "--" means all following arguments are not options, even if
they start with a dash.

> me@ant(26)$ env | grep -F '-g'
> grep: invalid option -- 'g'

Same as above.

> me@ant(28)$ env | grep '\-g'
> CFLAGS=-g

grep sees the argument starting with a backslash, it is not an option,
therefore it is the regexp. But backshash-dash could have had a special
semantic, like backslash-parentheses.

> me@ant(29)$ env | grep '-g'
> grep: invalid option -- 'g'

Same as above.

> me@ant(30)$ env | grep "-g"
> grep: invalid option -- 'g'

Same as above.

Regards,

-- 
  Nicolas George

[toc] | [prev] | [next] | [standalone]


#199453

FromJoe Pfeiffer <pfeiffer@cs.nmsu.edu>
Date2018-08-27 20:10 +0200
Message-ID<wru7E-1oD-13@gated-at.bofh.it>
In reply to#199429
What's tripping you up is that some processing is being done by the
shell before grep ever sees your pattern.  Taking that into account,
what grep is seeing is:

songbird <songbird@anthive.com> writes:

> me@ant(25)$ env | grep -F "-g"
grep -F -g
> grep: invalid option -- 'g'
> Usage: grep [OPTION]... PATTERN [FILE]...
> Try 'grep --help' for more information.
> me@ant(26)$ env | grep -F '-g'
grep -F -g
> grep: invalid option -- 'g'
> Usage: grep [OPTION]... PATTERN [FILE]...
> Try 'grep --help' for more information.
> me@ant(27)$ env | grep -F 'CFL'
> CFLAGS=-g
grep -F CFL
> me@ant(28)$ env | grep '\-g'
> CFLAGS=-g
grep \-g
(I'll note that in this case you need the quotes or the shell would have
stripped the \ .  I'm guessing this one is doing what you want)
> me@ant(29)$ env | grep '-g'
grep -g
> grep: invalid option -- 'g'
> Usage: grep [OPTION]... PATTERN [FILE]...
> Try 'grep --help' for more information.
> me@ant(30)$ env | grep "-g"
grep -g
> grep: invalid option -- 'g'
> Usage: grep [OPTION]... PATTERN [FILE]...
> Try 'grep --help' for more information.
>
>
> songbird

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.user


csiph-web