Unix Shell - quoting,variable substitution and command substitution

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > January 2007 > quoting,variable substitution and command substitution





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author quoting,variable substitution and command substitution
hantechs@gmail.com

2007-01-27, 7:22 am

I'm confused with the result of the following script:
cmd="echo abc | grep abc"
echo $($cmd)
it's output in my linux box is :
abc | grep abc
It seems that the command substitution treats the cmd's value as one
command unit(not two commands combined with '|') with arguments
separated by whitespace. Why? If it is because the quoting, I think it
should treats the whole string as a command name, just as :
echo $("echo abc | grep abc")
Can somebody explain it? Thanks.

Bruce Barnett

2007-01-27, 7:21 pm

"hantechs@gmail.com" <hantechs@gmail.com> writes:

> I'm confused with the result of the following script:
> cmd="echo abc | grep abc"


[snip]

> It seems that the command substitution treats the cmd's value as one
> command unit


You didn't use command substitution. You used simple (weak) quotes.

Change " to `



--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com