[TriLUG] bash question

Jeremy Portzer jeremyp at pobox.com
Wed Oct 17 19:11:35 EDT 2007

Joseph Mack NA3T wrote:
> On Wed, 17 Oct 2007, David Brain wrote:
>> Smells nasty, but...
>> CMDA="ls |"
>> CMDB="wc -l"
>> bash -c "$CMDA$CMDB"
> hmm, it's the "-c" that I've been missing. If I leave it 
> out, then I get the same error that lead to my original 
> posting.

You can also use "eval"

CMDA="ls |"
CMDB="wc -l"
eval "$CMDA$CMDB"

This avoids starting up a whole new bash process (though I think the 
evaluated command is still considered a "subshell" - but at least not a 
separate process.)

"eval" is a command available in most scripting languages that is used 
to compile/run an arbitrary command based on calculated data.  It's a 
useful construct in many situations though it can be over-used, and can 
be a major security issue if the data to be evaluated is un-trusted.


More information about the TriLUG mailing list