adding path to $PATH

2003-12-10 Thread Pablo Cusnir
Hi, 

Is there a way using Perl to add to the environment variable PATH a new path, and that 
addition will be valid after the script is ran and not only for the script's scope.
I'm working in cshell in Solaris 5.8
The regular way to do it in the shell is: 

 setenv PATH my_add_path:$PATH

I tried using: 

system(setenv .);

and also:

system (csh setenv .);

Thanks,



Best regards, 

Pablo


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: adding path to $PATH

2003-12-10 Thread Helgi Briem
Pablo Cusnir wrote:
 Hi,
 
 Is there a way using Perl to add to the environment variable PATH a
 new path, and that addition will be valid after the script is ran and
 not only for the script's scope.  
 I'm working in cshell in Solaris 5.8
 The regular way to do it in the shell is:

Yours is a Frequently Asked Question.  As such,
it is answered in the perlfaq documents that come
bundled with every distribution of Perl.  They can
be browsed and searched with the perldoc program.

Have a look at perldoc -q environment

This will direct you to the Unix FAQ, for example here:

http://www.faqs.org/faqs/unix-faq/faq/part2/
(Question 2.8)

I cannot find the supposedly much more detailed answer
in ftp.wg.omron.co.jp/pub/unix-faq/docs/script-vs-env

In short, this should be impossible, but can be done
through trickery.

-- 
Helgi Briem T?knideild  Landss?minn EHF
[EMAIL PROTECTED]
S?mi: 550-7466 GSM: 896-7466

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: adding path to $PATH

2003-12-10 Thread Dan Anderson
On Wed, 2003-12-10 at 01:09, Pablo Cusnir wrote:
 Hi, 
 
 Is there a way using Perl to add to the environment variable PATH a new path, and 
 that addition will be valid after the script is ran and not only for the script's 
 scope.
 I'm working in cshell in Solaris 5.8
 The regular way to do it in the shell is: 
 
  setenv PATH my_add_path:$PATH
 
 I tried using: 
 
 system(setenv .);
 
 and also:
 
 system (csh setenv .);

You'd need to add it to the CSH equivalent of the .bashrc found in users
directory, or /etc/bashrc for it to persist.

-Dan


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: adding path to $PATH

2003-12-10 Thread drieux
On Dec 9, 2003, at 10:09 PM, Pablo Cusnir wrote:

Is there a way using Perl to add to the environment
variable PATH a new path, and that addition will be
valid after the script is ran and not only for the script's scope.
I'm working in cshell in Solaris 5.8
let me see IF I get your idea.

I have a command say add_path  so that
you could do something like
vladimir: 70:] echo $PATH
/usr/local/bin:/usr/X/bin:/usr/bin
vladimir: 71:] add_path
vladimir: 72:] echo $PATH
/happy/place/here:/usr/local/bin:/usr/X/bin:/usr/bin
vladimir: 73:]
that's not really going to happen, since you want to
change the environment of the currently running process
by having a sub-process 'signal it'...
What is relatively 'easy' to do, is to create a sub_shell
that will run with a different set of environmental variables.
vladimir: 89:] echo $BOB
BOB: Undefined variable
vladimir: 90:] perl add_path
vladimir% echo $BOB
my bob here
vladimir% exit
vladimir% vladimir: 91:] sed 's/^/### /' add_path
### #!/usr/bin/perl -w
### use strict;
###
### my $path = '/happy/place/here';
### $ENV{PATH} = $path . : . $ENV{PATH} ;
### $ENV{BOB} = my bob here;
### exec(/usr/bin/csh -f);
vladimir: 92:]
This is a trick I use when I am trying to run some
'alternative environment' than my default home shell.
But as you notice, it is using 'exec()' to replace the
script space a csh that will not source my .login
and .cshrc file. It also means that I have a 'double exit'
case, where I have to exit out of the current shell
and then out of my 'default login shell'.
Remember it is easier to change the behavior of a sub_shell
than it is to try to signal upwards to some calling shell.
Try not to go that way...
ciao
drieux
---

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: adding path to $PATH

2003-12-10 Thread Robert Brown
drieux writes:
  
  On Dec 9, 2003, at 10:09 PM, Pablo Cusnir wrote:
  
   Is there a way using Perl to add to the environment
   variable PATH a new path, and that addition will be
   valid after the script is ran and not only for the script's scope.
   I'm working in cshell in Solaris 5.8
  
  let me see IF I get your idea.
  
  I have a command say add_path  so that
  you could do something like
  
   vladimir: 70:] echo $PATH
   /usr/local/bin:/usr/X/bin:/usr/bin
   vladimir: 71:] add_path
   vladimir: 72:] echo $PATH
   /happy/place/here:/usr/local/bin:/usr/X/bin:/usr/bin
   vladimir: 73:]
  
  that's not really going to happen, since you want to
  change the environment of the currently running process
  by having a sub-process 'signal it'...


I am not a c-shell guy, but in then Bourne shell, or in bash, you
could accomplish what you want in a similar fashion thus:

# instead of add_path being called directly, you can do this:
export PATH=`add_path`:$PATH

The back-quotes perform what lispers call a splice macro.  The value 
that is returned on add_path's stdout replaces the text or `add_path`
so that it does what you want.  So add_path might look something like
this: 

#!/bin/bash

# add_path -- return a path to add to PATH

echo /some/unusual/path:/another/one:/and/so/forth

I know there is a similar construct in csh, but I do not remember what 
it is.

I hope this is at least some help.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: adding path to $PATH

2003-12-10 Thread Tom Kinzer
in korn it would be:

export PATH=$(add_path):$PATH


-Original Message-
From: Robert Brown [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 10, 2003 3:20 PM
To: drieux
Cc: Perl Perl
Subject: Re: adding path to $PATH


drieux writes:
  
  On Dec 9, 2003, at 10:09 PM, Pablo Cusnir wrote:
  
   Is there a way using Perl to add to the environment
   variable PATH a new path, and that addition will be
   valid after the script is ran and not only for the script's scope.
   I'm working in cshell in Solaris 5.8
  
  let me see IF I get your idea.
  
  I have a command say add_path  so that
  you could do something like
  
   vladimir: 70:] echo $PATH
   /usr/local/bin:/usr/X/bin:/usr/bin
   vladimir: 71:] add_path
   vladimir: 72:] echo $PATH
   /happy/place/here:/usr/local/bin:/usr/X/bin:/usr/bin
   vladimir: 73:]
  
  that's not really going to happen, since you want to
  change the environment of the currently running process
  by having a sub-process 'signal it'...


I am not a c-shell guy, but in then Bourne shell, or in bash, you
could accomplish what you want in a similar fashion thus:

# instead of add_path being called directly, you can do this:
export PATH=`add_path`:$PATH

The back-quotes perform what lispers call a splice macro.  The value 
that is returned on add_path's stdout replaces the text or `add_path`
so that it does what you want.  So add_path might look something like
this: 

#!/bin/bash

# add_path -- return a path to add to PATH

echo /some/unusual/path:/another/one:/and/so/forth

I know there is a similar construct in csh, but I do not remember what 
it is.

I hope this is at least some help.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: adding path to $PATH

2003-12-10 Thread drieux
On Dec 10, 2003, at 3:06 PM, drieux wrote:
On Dec 9, 2003, at 10:09 PM, Pablo Cusnir wrote:

Is there a way using Perl to add to the environment
variable PATH a new path, and that addition will be
valid after the script is ran and not only for the script's scope.
I'm working in cshell in Solaris 5.8
[..]

Robert, Tom, thank you for the advice,
and the good intentions, but forgive me
if I go back over what I posted to
demonstrate a solution, complete with
executing it to perchance go back over
a series of basic issues.
The critical part of the OP's query is

	valid after the script is ran and not only for the script's scope

Unfortunately this is almost FAQ country, since
almost every 'scripter' notices that it would be
cooler IF they could do something like that. But
they do not always think about which part of the
process they are really trying to 'fix'.
Both of you saved the 'demonstration' portion of my
response to the OP, where I tried to illustrate the
idea of what the OP seems to have been asking. But
without actually noting the portion of the live
run code:
vladimir: 89:] echo $BOB
BOB: Undefined variable
vladimir: 90:] perl add_path
vladimir% echo $BOB
my bob here
vladimir%
the prompt shifts from the 'cool' csh style
defined in my .login as
	set prompt=`Hostname`: \!:] 

back to a 'system default style' as

	vladimir%

that occurred because the perl code:

vladimir: 91:] sed 's/^/### /' add_path
### #!/usr/bin/perl -w
### use strict;
###
### my $path = '/happy/place/here';
### $ENV{PATH} = $path . : . $ENV{PATH} ;
### $ENV{BOB} = my bob here;
### exec(/usr/bin/csh -f);
vladimir: 92:]
really does exec() a csh with the -f flag,
so that the newly spawned shell will NOT go back
and resource my .login and .cshrc files, so that
the '$ENV{PATH} = $path . : . $ENV{PATH} ;' will
pre-pend the value for all sub-sequent shells.
{ note, yes, we could expand that code to
a. test that $path existed in the $ENV{PATH}
b. if not then to update the .login/.cshrc as appropriate
c. then exec ourselves
}
The point of this drill is three fold:

a. IF the OP wanted to simply edit their
.login and/or .cshrc file to fix the
PATH line, then they have already been
informed of that.
{ someone even was polite enough to point to
one of the canonical FAQ's about this. }
b. the problem of trying to execute a command in
a shell that is, by it's very nature, being
executed in a 'sub_shell' will be HARD PRESSED
to go back and 'fix' the environment of the spawning shell
irregardless of the nature of the coding language used.
{ since technically the 'environment' is part of the process
space information, there is merely the issue of gaining
access to that information and bit twiddling it.
		Not something I will advocate while sober. }

	c. we all need to work on our reading and writing skills.

The perl add_path I hacked is derived from a much
older piece of ksh that I used:
vladimir: 62:] sed 's/^/### /' goMars
### #!/bin/ksh
###
### #
### # a way to play around in the Happy Mars Land Game
### #
###
### CommonDefFile=${HOME}/etc/drieuxTool.dfn
###
### if [ -f ${CommonDefFile} ]
### then
### . ${CommonDefFile}
### else
### echo unable to find  ${CommonDefFile}
### exit
### fi
###
### PS=HappyMars  
### export PS
### ENV=${HOME}/.mars.kshrc
### export ENV
###
### ksh
###
### exit
vladimir: 63:]
This way I could keep my default 'csh' login shell,
clean from all of that Foo CommonDefFile Definitions
as well as the .mars.kshrc set of ENV values, while
still giving me a 'work around' that would let me
flop into mars for doing certain types of work.
The reason I did not want to gobbledeGook up my
lovely .cshrc/.login file is that it is unpleasantly
bloated enough as it is so that it solves on the
fly which set of *nix ThingiePoos are in play based
upon the underlying type/version of *nix the file
is invoked on... { don't ask. MORE deep seated
unresolved cross platform compatibility issues.
Not to mention odd divergences within the linux
sub-cult of the *nix cults... }
Any Questions?

ciao
drieux
---

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response