BASH question: executing a cmd with a pipe that is in a
variable
Kevin D. Clark
clark_k at pannaway.com
Tue Aug 9 15:42:00 EDT 2005
Larry Cook writes:
> I'm being stupid! Can someone please help?
>
> I've got a BASH script with the following:
>
> CMD="zcat myfile | tar xf -"
> $CMD
>
> This puts zcat's output to stdout, rather than piping it to tar like I
> want.
This is because the shell's order of operations is different than what
you think it is. The man pages describes this in gory detail.
> Now I'm sure this is how it *should* work. :-( Unfortunately, I
> can't figure out how to get it to work like I want.
You could either just invoke "zcat myfile | tar xf -" directly (but I
guess you have some reason why you can't do that) or else you could
just try "eval $CMD".
Hope this helps,
--kevin
--
GnuPG ID: B280F24E And the madness of the crowd
alumni.unh.edu!kdc Is an epileptic fit
-- Tom Waits
More information about the gnhlug-discuss
mailing list