|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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?". |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
> > 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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
"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 |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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? |
|
![]() |
| Outils de la discussion | |
|
|