[Gllug] Bash: Escaping a *

C. Cooke ccooke at gkhs.net
Thu Jul 1 15:26:05 UTC 2004


On Tue, 2004-06-29 at 11:05, Pete Ryland wrote:
> For arrays in bash, you can use a subscript of @, e.g. ${arrayname[@]} which
> will expand each array member to a seperate word similarly to "$@".  That
> gives you about the closest thing to what you want.  That is:
> 
> OPTS=(-a -b -c "--silly multi word option")
> 
> /usr/bin/program ${OPTS[@]} "$foo"

That's not actually safe...

With bash: 

${OPTS[@]} would be the entire contents, unquoted.
${OPTS[*]} is the same.

"${OPTS[*]}" is the entire contents, all quoted as one string

"${OPTS[@]}" is the contents, each item quoted individually.


-- 
Charles Cooke, Sysadmin

-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list