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} from man bash Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash. Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, and \. The characters $ and ` retain their special meaning within double quotes. The backslash retains its special meaning only when followed by one of the following characters: $, `, ", \, or <newline>. A double quote may be quoted within double quotes by preceding it with a backslash. > > 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 >
signature.asc
Description: Digital signature
-- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html