[R] OT UNIX grep question

Jan T. Kim jtk at cmp.uea.ac.uk
Thu Aug 10 14:49:51 CEST 2006


On Thu, Aug 10, 2006 at 08:51:36AM -0300, Rolf Turner wrote:
> francoisromain at free.fr wrote:
> 
> > You have to learn about regular expressions. Then you'll come up with
> > something like :
> > 
> > grep "^dog$" /usr/share/dict/words
> 
> *You* have to learn about shell syntax.  The foregoing doesn't
> work; it gives an ``Illegal variable name.'' error.  To protect
> against the shell interpretation of the dollar sign you have
> to use *single* quotes.
> 
> 		grep '^dog$' /usr/share/dict/words
> 
> *does* work.  (Try it!)

you're perfectly right about single quotes being the correct thing to use
here, but not all shells are insisting on linguistic correctness the way
[t]csh does. bash leaves constructs that it cannot expand as they are, so
the variant with double quotes does work as expected with bash (although
through a mechanism that might be unexpected by most).

Best regards, Jan
-- 
 +- Jan T. Kim -------------------------------------------------------+
 |             email: jtk at cmp.uea.ac.uk                               |
 |             WWW:   http://www.cmp.uea.ac.uk/people/jtk             |
 *-----=<  hierarchical systems are for files, not for humans  >=-----*



More information about the R-help mailing list