[Gllug] Bash: Escaping a *

Russell Howe rhowe at wiss.co.uk
Sat Jun 26 23:53:04 UTC 2004


On Sat, Jun 26, 2004 at 09:13:08PM +0100, Darren Beale wrote:
> Dean Wilson wrote:
> 
> >Try echo "$SQL" instead.
> 
> Perfect, thanks
> 
> ;D

Unquoted shell variables are an accident waiting to happen.

Imagine if $SQL somehow managed to contain "`rm -rf ~`".

I'll leave it as an exercise to the reader to see what that does...

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?

-- 
Russell Howe     | Why be just another cog in the machine,
rhowe at wiss.co.uk | when you can be the spanner in the works?
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list