On Sat, Oct 18, 2008 at 5:53 PM, Vern Ceder <[EMAIL PROTECTED]> wrote:
> No, it's evaluating an expression. "x=something" isn't a command, it's an
> expression. While both "ifconfig" and "x=something" work at the commandline,
> bash doesn't try to interpret the contents of its variables, so trying to
> "run" $evalstring will always cause it to look for a command "x=something",
> if that makes sense.
>
> Cheers,
> Vern

So, a command is an expression, but an expression is not necessarily a command?

[EMAIL PROTECTED]:~$ getipcommand="ifconfig eth1 | grep inet\ addr | cut -d :
-f2 | cut -d \" \" -f1"
[EMAIL PROTECTED]:~$ eval $getipcommand
192.168.2.129
[EMAIL PROTECTED]:~$ $getipcommand
|: Unknown host
ifconfig: `--help' gives usage information.

So my pipeline is EVALuated as I would expect it because it is an
expression, but when it is expanded by bash when I "run"
$getipcommand, it is interpreted not as an expression but as a single
command with everything being an argument to it, including the pipes?

[EMAIL PROTECTED]:~$ ipcom1="ifconfig eth1"
[EMAIL PROTECTED]:~$ ipcom2="grep inet\ addr"
[EMAIL PROTECTED]:~$ ipcom3="cut -d : -f2"
[EMAIL PROTECTED]:~$ ipcom4="cut -d \" \" -f1"
[EMAIL PROTECTED]:~$ eval $ipcom1 | eval $ipcom2 | eval $ipcom3 | eval $ipcom4
192.168.2.129

Ok, so that makes sense, now what about this?:

[EMAIL PROTECTED]:~$ $ipcom1 | $ipcom2
grep: Trailing backslash

So, it's running the commands, but not piping them right. However, if
I EVALuate the second one, it's ok.

[EMAIL PROTECTED]:~$ $ipcom1 | eval $ipcom2
          inet addr:192.168.2.129  Bcast:192.168.2.255  Mask:255.255.255.0

So, it seems that in order for piping in to work right, $ipcom2 needs
to be an expression and not a command?

Simón

_______________________________________________
Fwlug mailing list
[email protected]
http://fortwaynelug.org/mailman/listinfo/fwlug_fortwaynelug.org

Reply via email to