PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Error using "xargs eval"
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Error using "xargs eval"

Réponse
 
LinkBack Outils de la discussion
Vieux 07/09/2007, 15h02   #1
John
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Error using "xargs eval"

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

  Réponse avec citation
Vieux 07/09/2007, 15h42   #2
Miles
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Error using "xargs eval"

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



  Réponse avec citation
Vieux 07/09/2007, 19h09   #3
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Error using "xargs eval"

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
  Réponse avec citation
Vieux 11/09/2007, 10h03   #4
John
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Error using "xargs eval"

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.

  Réponse avec citation
Vieux 11/09/2007, 17h17   #5
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Error using "xargs eval"

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.
  Réponse avec citation
Vieux 11/09/2007, 18h21   #6
Cyrus Kriticos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Error using "xargs eval"

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 09h46.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12477 seconds with 14 queries