[PLUG] More Scripting Fun!

Jason Van Cleve jason at vancleve.com
Sat Jun 22 07:33:05 PDT 2002


Hi ho,

Me again, with a subtle bash befuddlement.  I want to allow a variable
to control how a command's output is redirected, so I figure I'll just
append the variable to the command, right?  If the variable is empty, no
problem; and if it contains ">& /dev/null", it should redirect all the
output into the Great Unknown, right?  Alas, it is not so.

I'm working with bash 2.05a, for your info, and I'm inside a function in
a script file, where I have this line:

	$COMMAND $* ${COMMAND_SUFFIX}

$COMMAND contains the path to apachectl, $* contains simply "start", and
$COMMAND_SUFFIX is defined thus:

	COMMAND_SUFFIX='>& /dev/null'

And the unexpected result is that apachectl spews out it's "usage:"
message twice in a row, apparently once for ">&" and once for
"/dev/null".  If, on the other hand, I substitute the presumably
equivalent line:

	$COMMAND $* >& /dev/null

then the command executes silently, as desired.  So I'm missing some
subtlety of variable expansion, because I'm at a complete loss with this
one.  What's going on here, and more importantly, is there a clean way
around this problem?  All I can think to do is to split $COMMAND_SUFFIX
into multiple variables.

What do you fellows make of this?

--Jason Van Cleve




More information about the PLUG mailing list