command substitution and the pipe

command substitution and the pipe

am 27.10.2007 01:22:05 von garyjefferson123

suppose I have prepared a command* such as:

~$ cmd="echo \"something1 : something2\" | awk '{print \$1, \$2}'"

and now I want to execute it as if it had been typed at the bash
prompt:

~$ $cmd

which produces:

"something1 : something2" | awk '{print $1, $2}'

I can't see how to get backticks or $() to work for me here, either.

Is there some trick to use to get command substitution to evaluation
the pipe and do what I'm looking for here (besides echoing the command
to a file and then execing it inside a bash prompt)?

Thanks,
Gary



*nevermind that there are other ways to accomplish this without the
pipe -- the sufficiently more complicated example that I'm trying to
solve *cannot* be done without the pipe. The question I'm asking here
is not "how do I do this without the pipe?" it is "how do I get bash
command substitution to work with the pipe in the constructed command?"

Re: command substitution and the pipe

am 27.10.2007 03:12:15 von Barry Margolin

In article <1193440925.649516.220330@o80g2000hse.googlegroups.com>,
garyjefferson123@gmail.com wrote:

> suppose I have prepared a command* such as:
>
> ~$ cmd="echo \"something1 : something2\" | awk '{print \$1, \$2}'"
>
> and now I want to execute it as if it had been typed at the bash
> prompt:
>
> ~$ $cmd
>
> which produces:
>
> "something1 : something2" | awk '{print $1, $2}'
>
> I can't see how to get backticks or $() to work for me here, either.
>
> Is there some trick to use to get command substitution to evaluation
> the pipe and do what I'm looking for here (besides echoing the command
> to a file and then execing it inside a bash prompt)?

eval "$cmd"

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***