[colug-432] Question about grep and using " " in bash
Rob Funk
rfunk at funknet.net
Wed Apr 15 11:01:40 EDT 2015
zach villers wrote:
> Is there a difference between;
>
> ls -l | grep ^...s
>
> AND
>
> ls -l | grep "^...s"
>
> *trying to find files with setuid permission*
>
> A trainer told me using quotes with the grep statement was necessary,
> but it doesn't seem to be.
Without the quotes, the shell will try to interpret your search
pattern in its own ways that have nothing to do with the search you're
trying to do. In this case that's harmless (nothing for it to
interpret), but if there are spaces or dollar signs or vertical-bars
or ampersands or question marks or asterisks or
less-than/greater-thans... and so on. There are many many symbols that
might be in a regular expression that a shell might interpret itself.
It's safest just to ALWAYS put it in quotes.
Then there's the question of which quotes. With double-quotes, the
shell will still try to interpret dollar-signs. You're safest using
double-quotes.
More information about the colug-432
mailing list