Re: The shell and my scripts

2005-07-29 Thread David Ledger
More to the point, environment variables are part of every process (rather
than just a login session). A process inherits variables with values from the
environment of its parent when it starts. From then on they're independent of
the parent. They're not a bolt-on but a fundamental part of the Unix process
design.

David


Kim Helliwell [EMAIL PROTECTED] wrote:

 The environment variables have nothing to do with the shell.
 The only thing the shell does is give you a way to set environment
 variables, and different shells have different syntax for that. But
 environment variables are a property of your login session, not
 of the shell.
 
 So the short answer is: Perl does not need to know or care about what
 shell you're running in (although that's available as the environment
 variable SHELL). Perl scripts just get the environment variables for
 free as part of the startup.
 
 Hope that answers it.
 
 Kim Helliwell
 [EMAIL PROTECTED]
 Homepage: http://homepage.mac.com/kimgh
 
 On Jul 28, 2005, at 8:10 PM, John Horner wrote:
 
  Recently there was a change at work -- all http access now needs to  
  go through a proxy.
 
  So if I have a script using LWP::UserAgent or similar, I have to add
 
  $UA-proxy( ['http'] , 'http://proxy.fake.com:8080' );
 
  to all my scripts. Which is a big pain. So a *NIX guy said you  
  shouldn't need to do that if you can add an environment variable to  
  your shell.
 
  So, as I use tcsh, not bash, which is the default nowadays, I added  
  this to .tcshrc:
 
  setenv http_proxy http://proxy.fake.com:8080
 
  and it seemed to work, but leaving aside the specifics of the  
  scripts, how would Perl know that I use tcsh, not bash? Isn't  
  that a preference of the Terminal app, not of me as a user? A  
  script run as a cron job, does it run using all the environment  
  variables as if I'd typed its name into the Terminal? What about a  
  script run from BBEdit? What if I su root and run it?
 
  I'd really appreciate someone explaining the relationship of script  
  to shell and user.
 
 
 
 
 





Re: The shell and my scripts

2005-07-29 Thread Sherm Pendley

On Jul 28, 2005, at 11:10 PM, John Horner wrote:

and it seemed to work, but leaving aside the specifics of the  
scripts, how would Perl know that I use tcsh, not bash?


As others have already said, Perl knows there's an environment  
variable, but it neither knows nor cares how that variable got set.



Isn't that a preference of the Terminal app, not of me as a user?


Actually, no. It's a preference of the user. If you log in by other  
means - X11's xterm, or remotely through ssh, for instance - the same  
preference will be used.


A script run as a cron job, does it run using all the environment  
variables as if I'd typed its name into the Terminal?


No. As it says in man 5 crontab, only LOGNAME (aka USER on some  
systems), HOME, and SHELL are set. You may set others by adding  
name=value pairs to your crontab file.


See man 5 crontab for details.


What about a script run from BBEdit?


BBEdit is a GUI app, and GUI apps don't use your login shell. To  
define environment variables to be used by GUI apps, have a look at  
this QA from Apple:


http://developer.apple.com/qa/qa2001/qa1067.html


What if I su root and run it?


It depends. If you simply su to root, you'll keep the same  
environment. But, if you su - (note the dash), it's like you're  
starting a separate new login session - root's own user login scripts  
are run, and nothing is inherited.


Sudo begins with an inherited environment, but modifies it heavily -  
have a look at the Security Notes section in man sudo for details.


sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org



Re: The shell and my scripts

2005-07-29 Thread Doug McNutt
At 08:08 -0400 7/29/05, Sherm Pendley wrote:
On Jul 28, 2005, at 11:10 PM, John Horner wrote:
What about a script run from BBEdit?

BBEdit is a GUI app, and GUI apps don't use your login shell. To  define 
environment variables to be used by GUI apps, have a look at  this QA from 
Apple:

BBEdit also allows BBEdit worksheets which are a bit like Apple's MPW using 
ENTER to execute selected text as shell commands. If you are using one of those 
an instance of your selected shell, tcsh, is associated with each open 
worksheet. On opening a worksheet your ~/.tcshrc is sourced and you can set 
environment variables there. Your tcsh login script is NOT run.

It's probably better to create a $HOME/.MacOSX/environment.plist file but watch 
out for the public tcsh startup files in /etc/. As delivered they can overwrite 
your selections in the plist especially for $PATH. The plist is read only at 
login-to-Aqua time. If you change it you must logout and login again to see the 
changes.

Things are better now that it's UNIX underneath. Just ask Steve.
-- 

--  Halloween  == Oct 31 == Dec 25 == Christmas  --