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 > Accessing params called by a shell script
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Accessing params called by a shell script

Réponse
 
LinkBack Outils de la discussion
Vieux 25/03/2008, 20h12   #1
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Accessing params called by a shell script

On 2008-03-25, worldcyclist@gmail.com wrote:
> Hello everyone!
> I am using a bash shell script that accepts command line parms.
> For example call it "cars.sh" and it accepts a car name through $1
> Later in the script I need to have this script to call another script
> to return
> multiple parms. In fact it's a perl script (used for it's hashing
> abilities) that if you were to call it would give you this....
>
> ./return_car_values.pl Jeep
> Wrangler Green 1995
>
> The question is, how would I then parse "Wrangler", "Green" and "1995"
> into arguments by the calling program..
>
> Example program is below...
> -------------------------------------------------------
> #!/bin/bash
> CARS=$1
> ...
> ...
> `./return_car_values.pl $1`
> ------------------------------------------------------
>
> I guess my question is how do I accomplish this....
> ($MODEL, $COLOR, $YEAR) = `./return_car_values $1`


set -f
set -- `./return_car_values.pl $1`
MODEL=$1 COLOR=$2 YEAR=$3


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 25/03/2008, 20h15   #2
worldcyclist@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Accessing params called by a shell script

Hello everyone!
I am using a bash shell script that accepts command line parms.
For example call it "cars.sh" and it accepts a car name through $1
Later in the script I need to have this script to call another script
to return
multiple parms. In fact it's a perl script (used for it's hashing
abilities) that if you were to call it would give you this....

../return_car_values.pl Jeep
Wrangler Green 1995

The question is, how would I then parse "Wrangler", "Green" and "1995"
into arguments by the calling program..

Example program is below...
-------------------------------------------------------
#!/bin/bash
CARS=$1
....
....
`./return_car_values.pl $1`
------------------------------------------------------

I guess my question is how do I accomplish this....
($MODEL, $COLOR, $YEAR) = `./return_car_values $1`

Many thanks!
JC


  Réponse avec citation
Vieux 25/03/2008, 20h40   #3
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Accessing params called by a shell script

worldcyclist@gmail.com wrote:

> I guess my question is how do I accomplish this....
> ($MODEL, $COLOR, $YEAR) = `./return_car_values $1`


I don't think you can do that directly with sh, however you can have those
values assigned as positional parameters, eg (assuming return_car_values.pl
returns "model1 red 2005")

ret=`return_car_values.pl`

eval set -- "$ret"

# now $1, $2 and $3 are set to "model1", "red" and "2005" respectively

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
  Réponse avec citation
Vieux 25/03/2008, 21h12   #4
worldcyclist@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Accessing params called by a shell script

A very public thanks to Chris for this fix and the heads up on the
book! Also thanks to pk, I didn't try your fix but Chris' worked right
off the bat.
Really, it's great there are folks like you that out the clueless
like myself.
JC

On Mar 25, 3:40 pm, pk <p...@pk.invalid> wrote:
> worldcycl...@gmail.com wrote:
> > I guess my question is how do I accomplish this....
> > ($MODEL, $COLOR, $YEAR) = `./return_car_values $1`

>
> I don't think you can do that directly with sh, however you can have those
> values assigned as positional parameters, eg (assuming return_car_values.pl
> returns "model1 red 2005")
>
> ret=`return_car_values.pl`
>
> eval set -- "$ret"
>
> # now $1, $2 and $3 are set to "model1", "red" and "2005" respectively
>
> --
> All the commands are tested with bash and GNU tools, so they may use
> nonstandard features. I try to mention when something is nonstandard (if
> I'm aware of that), but I may miss something. Corrections are welcome.


  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 05h21.


Édité par : vBulletin® version 3.7.3
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 ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09990 seconds with 12 queries