|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Sep 7, 9:02 am, John <jan...@gmail.com> 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: .. <your CGI SCRIPT> ie: <dot><space><your CGI SCRIPT> 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 <dot><space>./c) Step 3: root@ms:/tmp>echo $PARAM_mac aa:bb:cc:dd:11:22:33:44 Miles |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On 7 Sep, 20:09, Icarus Sparry <use...@icarus.freeuk.com> 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. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Tue, 11 Sep 2007 02:03:30 -0700, John wrote:
> On 7 Sep, 20:09, Icarus Sparry <use...@icarus.freeuk.com> 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. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|