>To: Jim Plank >Subject: Executing commands in shells > >Dr. Plank, > Sorry for this question but I'm having a hard time figuring exactly >what's happening in the following shell scenario > >Wael on duncan> sh >$ grep '\' /usr/dict/words >for >$ c="grep '\' /usr/dict/words" >$ echo $c >grep '\' /usr/dict/words >$ t="`$c`" >$ echo $t > >$ t=`"$c"` >grep '\' /usr/dict/words: not found > > >Now the questions : >1- Why in t="`$c`" do I get nothing as the output in $t ? >2- Why in t=`"$c"` do I get an error ? >3- If these two syntaxes are wrong, what's the right way of doing the >above (storing the command in a string then executing the string and >directing the output to another string) ? I can't answer the why part of it. It's the quotes that are throwing the shell off: $ b='grep \ /usr/dict/words' $ echo $b grep \ /usr/dict/words $ $b for Evidently when you execute a shell command from a variable, you don't have to worry about quoting: $ a='"' $ echo $a " $ Oddly, though, there are some metacharacters that do matter, like *: $ ls *.ps labs.ps $ c='ls *.ps' $ $c labs.ps $ If you're sick of trying alternatives, and want some cheap fixes, you can use "sh -c" or just pipe your command with quotes to the shell: $ grep '\' /usr/dict/words for $ c="grep '\' /usr/dict/words" $ echo $c grep '\' /usr/dict/words $ sh -c "$c" for $ echo $c | sh for $ Hope that helps, Jim