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 > Bourne shell: Executing a list in a separate shell
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Bourne shell: Executing a list in a separate shell

Réponse
 
LinkBack Outils de la discussion
Vieux 04/09/2007, 14h43   #1
bernd
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Bourne shell: Executing a list in a separate shell

Hello netties,

guess that the solution is really straightforward, but may be I am
just too blind at the moment:

I want to run a list of commands by executing a new Bourne shell
instance on one line. My testcode looks as follows:

> cat testscript.sh

echo hello
TESTVAR="This is a test"
export TESTVAR

When I run a new shell and supply the list "manually" to the shell I
can comprise them using braces without problems:

> /bin/sh
> { . testscript.sh ; echo $TESTVAR; }

hello
This is a test

If I try to do it "in one run" it does not work as I would like it to
work:

> /bin/sh { . testscript.sh echo $TESTVAR; }

syntax error: `}' unexpected
>


Is there a way in Bourne shell to accomplish execution (better:
sourcing) of a shell script, and let subsequent commands being
executed in the same environment as the script in the way indicated
above without supplying the list interactively to the shell (but like
a "/bin/sh -c" invocation? (which, BTW, does not work either)) .

Cheers


Bernd

  Réponse avec citation
Vieux 04/09/2007, 15h21   #2
hyperboogie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Bourne shell: Executing a list in a separate shell

On Sep 4, 4:43 pm, bernd <bew...@gmx.net> wrote:
> Hello netties,
>
> guess that the solution is really straightforward, but may be I am
> just too blind at the moment:
>
> I want to run a list of commands by executing a new Bourne shell
> instance on one line. My testcode looks as follows:
>
> > cat testscript.sh

>
> echo hello
> TESTVAR="This is a test"
> export TESTVAR
>
> When I run a new shell and supply the list "manually" to the shell I
> can comprise them using braces without problems:
>
> > /bin/sh
> > { . testscript.sh ; echo $TESTVAR; }

>
> hello
> This is a test
>
> If I try to do it "in one run" it does not work as I would like it to
> work:
>
> > /bin/sh { . testscript.sh echo $TESTVAR; }

>
> syntax error: `}' unexpected
>
>
>
> Is there a way in Bourne shell to accomplish execution (better:
> sourcing) of a shell script, and let subsequent commands being
> executed in the same environment as the script in the way indicated
> above without supplying the list interactively to the shell (but like
> a "/bin/sh -c" invocation? (which, BTW, does not work either)) .
>
> Cheers
>
> Bernd


try this:
/bin/sh -c 'myname=boogie;export myname;echo ${myname}'
boogie

be sure to use single quotes

  Réponse avec citation
Vieux 04/09/2007, 16h56   #3
bernd
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Bourne shell: Executing a list in a separate shell

On 4 Sep., 16:21, hyperboogie <hyperboo...@gmail.com> wrote:
> On Sep 4, 4:43 pm, bernd <bew...@gmx.net> wrote:
>
>
>
>
>
> > Hello netties,

>
> > guess that the solution is really straightforward, but may be I am
> > just too blind at the moment:

>
> > I want to run a list of commands by executing a new Bourne shell
> > instance on one line. My testcode looks as follows:

>
> > > cat testscript.sh

>
> > echo hello
> > TESTVAR="This is a test"
> > export TESTVAR

>
> > When I run a new shell and supply the list "manually" to the shell I
> > can comprise them using braces without problems:

>
> > > /bin/sh
> > > { . testscript.sh ; echo $TESTVAR; }

>
> > hello
> > This is a test

>
> > If I try to do it "in one run" it does not work as I would like it to
> > work:

>
> > > /bin/sh { . testscript.sh echo $TESTVAR; }

>
> > syntax error: `}' unexpected

>
> > Is there a way in Bourne shell to accomplish execution (better:
> > sourcing) of a shell script, and let subsequent commands being
> > executed in the same environment as the script in the way indicated
> > above without supplying the list interactively to the shell (but like
> > a "/bin/sh -c" invocation? (which, BTW, does not work either)) .

>
> > Cheers

>
> > Bernd

>
> try this:
> /bin/sh -c 'myname=boogie;export myname;echo ${myname}'
> boogie
>
> be sure to use single quotes- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -



It works. Thanks a lot!

  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 09h24.


É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,11674 seconds with 11 queries