[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: scripting question



On Wed, Apr 16, 2003 at 03:40:42PM +0200, David Jardine wrote:
> On Wed, Apr 16, 2003 at 12:23:46PM +0100, Colin Watson wrote:
> > On Tue, Apr 15, 2003 at 07:23:06PM -0700, Alvin Oga wrote:
> > > -- and be careful, that what you type on a command line will NOT
> > >    necessarily work in a bash script
> > > 
> > > 	root#  ls -la /home/foo  | grep -iv "ignore|this|and|that" 
> > > 
> > > 	will need to be 'escaped' in some scripts and not others
> > 
> > That's wrong just to start with. Use egrep if you want to use '|' for
> > alternatives. With grep, use '\|', and put single quotes around it, not
> > double. Double quotes are asking for trouble unless you explicitly want
> > their expansion effects.
> 
> Well,
> 
> 	grep foo "ignore\|this\|and\|that" -v
> 
> works for me but
> 
> 	grep foo 'ignore\|this\|and\|that' -v
> 
> doesn't.

Neither of those is right anyway (you've got the pattern and the
filename the wrong way round), so perhaps you could paste exactly what
you're doing?

(Actually, I was wrong anyway; \| doesn't become | inside double quotes,
although it *does* expand differently in ways which are often relevant
to regular expressions. See QUOTING in bash(1).)

-- 
Colin Watson                                  [cjwatson@flatline.org.uk]



Reply to: