On Mon, 13 Sep 2004 03:45 pm, Alexander Samad wrote:
> On Mon, Sep 13, 2004 at 03:20:37PM +1000, James Gray wrote:
> > On Mon, 13 Sep 2004 02:17 pm, Alexander Samad wrote:
> > > Hi
> > > Quick question for the list
> > >
> > > I am trying to do something like this
> > > #!/bin/bash
> > > SOMEVARIABLE
> > > VAR2="$( awk -F, "/$SOMEVARIABLE/ /some/pathtoafile/")"
> > >
> > > Now I have problems with my " I can't use ' because I want SOMEVARIABLE
> > > to be subsituted  I have tried
> > >
> > > VAR2="$( awk -F, \"/$SOMEVARIABLE/ /some/pathtoafile/\")"
> > >
> > > but it starts going haywire!
> > >
> > > Alex
> >
> > Have you tried protecting the variable from the shell per the "man bash"
> > instructions like this:
> > VAR2="$( awk -F, "/${SOMEVARIABLE}/ /some/pathtoafile/")"
> >
> > BTW - that line above looks a little odd.  I'd try it like this instead:
> > VAR2=`awk -F, '/${SOMEVARIABLE}/ /some/pathtoafile/'`
>
> $() iq equivilant to `'
> and I "" so as to make sure that the program doesn't have any space in
> the return to foul it up
>
> > The enclosing a variable between curly braces, eg, ${foo}  will force the
> > shell to expand the variable's content regardless of whether it is inside
> > single or double quotes. IIRC.
>
> well i just tried this
>
> TEST='HELLO'  echo '${TEST}'
> and it printed out this
> ${TEST}

*SHRUG* - that's why I said "IIRC"....which obviously I didn't :P  I don't do 
a lot of bash scripting any more...mostly Perl and Python :-/

Thanks for the object lesson in RTFM before putting one's foot in one's 
mouth! ;)

Cheers,

James
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to