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 > why setenv doesn't work with arg
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

why setenv doesn't work with arg

Réponse
 
LinkBack Outils de la discussion
Vieux 04/09/2007, 23h44   #1
JoshforRefugee
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut why setenv doesn't work with arg

setenv MY_BASELINE `ps -ef | grep BASELINE | grep -v grep | tail -1 '
seems to work correctly
but
ps -ef | grep BASELINE | grep -v grep | tail -1 | xargs setenv
MY_BASELINE
doesn't work

can someone tell me what's wrong
thanks

  Réponse avec citation
Vieux 05/09/2007, 04h15   #2
Maxwell Lol
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: why setenv doesn't work with arg

JoshforRefugee <ankitks@yahoo.com> writes:

> setenv MY_BASELINE `ps -ef | grep BASELINE | grep -v grep | tail -1 '
> seems to work correctly


because your current shell executes it

> but
> ps -ef | grep BASELINE | grep -v grep | tail -1 | xargs setenv
> MY_BASELINE
> doesn't work


Because you are launching a new shell, and change the envoenment in
that new shell, which executes.


  Réponse avec citation
Vieux 05/09/2007, 04h18   #3
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: why setenv doesn't work with arg

On Tue, 04 Sep 2007 15:44:16 -0700, JoshforRefugee wrote:

> setenv MY_BASELINE `ps -ef | grep BASELINE | grep -v grep | tail -1 '
> seems to work correctly
> but
> ps -ef | grep BASELINE | grep -v grep | tail -1 | xargs setenv
> MY_BASELINE
> doesn't work
>
> can someone tell me what's wrong
> thanks


There are at least two possible explanations, it would have ed if you
had shown us the output.

Reason number 1. You don't have a "setenv" program. Normally setenv is a
builtin for csh and tcsh.

Reason number 2. You are setting the environment variable, but it is in
an environment that is destroyed straight away. Your second syntax will
create a number of processes, at least 5, and maybe more. Each of these
processes will have a copy of the current environment, which they can
choose to alter. In particular the process running the "xargs" program
will have a copy. It will then typically create a new process to run the
"setenv" command, and this will have a copy of the environment from its
parent (the "xargs process"). The "setenv process" will alter its
environemnt, then exit, and that environment will be destroyed, The
original environment will be left unchanged. In contrast your first
syntax will create a number of processes, and the output of this will be
given to the setenv command *in the current shell*. As this is a builtin
command this will alter the environment of the current shell.

This question is essentially the same question as "why can't I write a
shell script that changes my current directory?".
  Réponse avec citation
Vieux 06/09/2007, 16h17   #4
JoshforRefugee
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: why setenv doesn't work with arg


>
> This question is essentially the same question as "why can't I write a
> shell script that changes my current directory?".


I am fairly new to unix env. Can you tell me why I can't write shell
script that changes my current dir

  Réponse avec citation
Vieux 06/09/2007, 16h28   #5
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: why setenv doesn't work with arg

JoshforRefugee wrote:
>>This question is essentially the same question as "why can't I write a
>>shell script that changes my current directory?".

>
>
> I am fairly new to unix env. Can you tell me why I can't write shell
> script that changes my current dir
>


Because, unless you use ". script", that shell script will execute in a
sub-shell so you'll be changing directory only within that sub-shell.
See question 22 in the FAQ:

http://cfaj.freeshell.org/shell/cus-faq-2.html#22

for more info.

Ed
  Réponse avec citation
Vieux 06/09/2007, 16h33   #6
Joachim Schmitz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: why setenv doesn't work with arg

"JoshforRefugee" <ankitks@yahoo.com> schrieb im Newsbeitrag
news:1189091832.344264.267980@r34g2000hsd.googlegr oups.com...
>
>>
>> This question is essentially the same question as "why can't I write a
>> shell script that changes my current directory?".

>
> I am fairly new to unix env. Can you tell me why I can't write shell
> script that changes my current dir

Because that shell script would run in a new shell (child process of your
current one), change directory there, but then that new shell ends and in
your old shell you're still in the old directory.

Unless you explicitly tell your current shell interpret that script itself,
e.g. by using the . command.

Bye, Jojo


  Réponse avec citation
Vieux 06/09/2007, 17h45   #7
Maxwell Lol
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: why setenv doesn't work with arg

JoshforRefugee <ankitks@yahoo.com> writes:


> I am fairly new to unix env. Can you tell me why I can't write shell
> script that changes my current dir


Let me add this - what happens when you launch several new shells, and
change the environment to be different in each one?

Is the parent of these shells suppose to change? To which environment exactly?


  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 02h33.


É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
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11718 seconds with 15 queries