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

Re: bash shell variables with spaces



On Mon, 2004-07-19 at 10:27, Zenaan Harkness wrote:
> Does anyone know why the following works:
> 
> #!/bin/sh -x
> FONT=-jmk-neep\ alt-medium-r-semicondensed-*-*-100-*-*-c-*-iso8859-15
> xterm -sl $BUFFER -fn $FONT -geometry 87x96+447+26

Sorry, the last line above should be:

xterm -sl $BUFFER -fn "$FONT" -geometry 87x96+447+26

Which also needs to be replaced in the two below, in which case all
three examples will work. And now I understand - the shell variable
value must "make it into" the shell variable, so it somehow needs to be
escaped - all three methods work for this (apparently, and so they
should).

On the subsequent line where the variable is expanded to make the
command to run, the expansion contains a space and must therefore be
somehow escaped. Double quotes does this.

Which raises the question - what if the expansion contains double quote
chars? Perhaps using double-backslash (or quad??) would do the trick?

> But neither of the following work:
> 
> #!/bin/sh -x
> FONT="-jmk-neep alt-medium-r-semicondensed-*-*-100-*-*-c-*-iso8859-15"
> xterm -sl $BUFFER -fn $FONT -geometry 87x96+447+26
> 
> #!/bin/sh -x
> FONT='-jmk-neep alt-medium-r-semicondensed-*-*-100-*-*-c-*-iso8859-15'
> xterm -sl $BUFFER -fn $FONT -geometry 87x96+447+26



Reply to: