[Gllug] Bash: Escaping a *

Pete Ryland pdr at createservices.com
Tue Jun 29 10:05:31 UTC 2004


On Sun, Jun 27, 2004 at 12:53:04AM +0100, Russell Howe wrote:
> Always quote your shell variables (the only exception being when you
> want to do something like:
> 
> OPTS=-a -b -c
> 
> /usr/bin/program $OPTS "$foo"
> 
> Anyone know a fancy way to do that safely? I know there's the special
> "$@" which expands to "$1" "$2" "$3" ... "$n" for parameters, but I
> don't think there's a generalised version, or is there?

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"

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




More information about the GLLUG mailing list