Error using "xargs eval"

Error using "xargs eval"

am 07.09.2007 16:02:45 von John

Hi,

I've got some problems using xargs together with eval, maybe because
it's not a regular command.

Suppose I have a CGI script which receives a MAC address. I want to
convert coded colons to colons. Right now I use something like this
for doing that:

echo "PARAM_mac=$PARAM_mac" | sed "s/%3A/:/g" > /tmp/tmp_mac$$
.. /tmp/tmp_mac$$

It works fine, but it uses the harddrive. So I would like to do
something like

echo "PARAM_mac=$PARAM_mac" | sed "s/%3A/:/g" | xargs eval

But that doesn't work since xargs doesn't understand how to execute
eval. Is there any standard solution for that kind of problem?

/ John

Re: Error using "xargs eval"

am 07.09.2007 16:42:27 von Miles

On Sep 7, 9:02 am, John wrote:
> Hi,
>
> I've got some problems using xargs together with eval, maybe because
> it's not a regular command.
>
> Suppose I have a CGI script which receives a MAC address. I want to
> convert coded colons to colons. Right now I use something like this
> for doing that:
>
> echo "PARAM_mac=$PARAM_mac" | sed "s/%3A/:/g" > /tmp/tmp_mac$$
> . /tmp/tmp_mac$$
>
> It works fine, but it uses the harddrive. So I would like to do
> something like
>
> echo "PARAM_mac=$PARAM_mac" | sed "s/%3A/:/g" | xargs eval
>
> But that doesn't work since xargs doesn't understand how to execute
> eval. Is there any standard solution for that kind of problem?
>
> / John

What about moving the dot to in front of the CGI script? So use:
..
ie:


I think this example shows how it might work:
Step 1:
root@ms:/tmp>cat c
#!/usr/bin/ksh93
eval 'PARAM_mac="aa:bb:cc:dd:11:22:33:44"'

Step 2:
root@ms:/tmp>. ./c
(Notice ./c)

Step 3:
root@ms:/tmp>echo $PARAM_mac
aa:bb:cc:dd:11:22:33:44

Miles

Re: Error using "xargs eval"

am 07.09.2007 20:09:37 von Icarus Sparry

On Fri, 07 Sep 2007 07:02:45 -0700, John wrote:

> Hi,
>
> I've got some problems using xargs together with eval, maybe because
> it's not a regular command.
>
> Suppose I have a CGI script which receives a MAC address. I want to
> convert coded colons to colons. Right now I use something like this for
> doing that:
>
> echo "PARAM_mac=$PARAM_mac" | sed "s/%3A/:/g" > /tmp/tmp_mac$$ .
> /tmp/tmp_mac$$
>
> It works fine, but it uses the harddrive. So I would like to do
> something like
>
> echo "PARAM_mac=$PARAM_mac" | sed "s/%3A/:/g" | xargs eval
>
> But that doesn't work since xargs doesn't understand how to execute
> eval. Is there any standard solution for that kind of problem?
>
> / John

The answer to the "eval" question is to do something like

sh -c "eval put_your_string_here"

The answer to what you actually want is

PARAM_mac=$(echo $PARAM_mac | sed "s/%3[Aa]/:/g" )

or even

PARAM_mac=${PARAM_mac//\%3[Aa]/:}

if you have a nice modern bash/zsh/ksh

Re: Error using "xargs eval"

am 11.09.2007 11:03:30 von John

On 7 Sep, 20:09, Icarus Sparry wrote:

> The answer to what you actually want is
>
> PARAM_mac=$(echo $PARAM_mac | sed "s/%3[Aa]/:/g" )
>
> or even
>
> PARAM_mac=${PARAM_mac//\%3[Aa]/:}
>
> if you have a nice modern bash/zsh/ksh

Thanks! That satisfies my basic interest of not using the disk drive.
But I'm still curious
why xargs is designed not to be able to use inbuilt commands.

Re: Error using "xargs eval"

am 11.09.2007 18:17:42 von Icarus Sparry

On Tue, 11 Sep 2007 02:03:30 -0700, John wrote:

> On 7 Sep, 20:09, Icarus Sparry wrote:
>
>> The answer to what you actually want is
>>
>> PARAM_mac=$(echo $PARAM_mac | sed "s/%3[Aa]/:/g" )
>>
>> or even
>>
>> PARAM_mac=${PARAM_mac//\%3[Aa]/:}
>>
>> if you have a nice modern bash/zsh/ksh
>
> Thanks! That satisfies my basic interest of not using the disk drive.
> But I'm still curious
> why xargs is designed not to be able to use inbuilt commands.

The question is simular to asking "why does the C compiler not use the
builtin commands of the shell?". xargs is a stand alone program, which
gathers up the input and executes commands. When it come to execute the
command it has got to find it, and you do not have a /bin/eval or a /usr/
bin/eval (and even if you did they would not work in the way that you
appear to hope they will).

There are other operating systems where the environment is either global
(MSDOS I think comes under this heading), or you can optionally share it
between processes (e.g. plan9), but unix is not one of these.

Re: Error using "xargs eval"

am 11.09.2007 19:21:17 von Cyrus Kriticos

John wrote:
>
> Suppose I have a CGI script which receives a MAC address. I want to
> convert coded colons to colons.
>
> Is there any standard solution for that kind of problem?

$ PARAM_mac="01%3A0C%3A21%3A33%3A2A%3A22"
$ PARAM_mac="${PARAM_mac//%3A/:}"
$ echo $PARAM_mac
01:0C:21:33:2A:22

--
Best regards | "The only way to really learn scripting is to write
Cyrus | scripts." -- Advanced Bash-Scripting Guide