BASH question: executing a cmd with a pipe that is in a variable
Steven W. Orr
steveo at syslang.net
Wed Aug 10 10:53:01 EDT 2005
On Tuesday, Aug 9th 2005 at 15:13 -0400, quoth Larry Cook:
=>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.
=>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've already gotten the solution to use the eval command. But I thought
it would be instructional to 'splain it so you know why.
Look at this example and it becomes more obvious.
foo='echo hello | cat'
if you say
$foo
you're expecting to see a hello. Instead you correctly see
hello | cat
i.e., what you're really getting is this
echo 'hello | cat'
which makes it perfectly obvious what's happening. If you really want the
command to be executed you need an eval to prevent the "myfile | tar xf -"
to all not be args 1 through 5 to zcat.
Sounds logical to a Vulcan...
--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
More information about the gnhlug-discuss
mailing list