Re: How to change shell valluables
Re: How to change shell valluables
- Subject: Re: How to change shell valluables
- From: Jonathan Prescott <email@hidden>
- Date: Tue, 28 Dec 2004 21:42:15 -0500
One of the guiding priniciples of Unix from the beginning is that all
shells inherit the environment variables from the environment from
which the shell was spawned. In traditional Unix implementations, the
first user process is the "login" process, which spawns a process
running your shell of choice as the "login" process. It's in this
process that the shell (csh, tcsh, sh, ash, bash, ksh, etc.) performs
login profile file processing (for example, tcsh reads in the csh.login
file, then the csh.cshrc file, then your .login file, finally, your
.tcshrc or .cshrc, etc.) as outlined in the man file. If you telnet
into your local machine from a Terminal or an xterm, you will see this
in action (Note: telnetting into a machine invokes the same process as
logging in. You start a new "login" process just as if you logged in
from a tty line. That's why environment variables don't propagate when
you telnet, even if you are telnetting into your own machine).
Now, logging into a Mac from the login window simply means the login
window program starts up (or is) the first user process, with the
environment variables set from the environment.plist by the login
window program (note I am distinguishing the login window program from
login, which still resides to support non-console logins), which it
reads just like the login shell reads in the contents of .tcshrc, etc..
Since all program invocations such as running an app, running a
Terminal shell, are really separate processes forked from the root (or
forked from processes forked from the root, etc.), they eventually
inherit the environment variables set in environment.plist (as well as
any changes you make through .cshrc, .tcshrc, .bashrc, files, etc. in
your profile). For applications started from the Finder, the only
environment you see is the variables defined in environment.plist since
it is not a shell program. The Terminal.app, the xterm application,
since they run shells normally, execute the login sequence of your
chosen shell, with the environment.plist variables instantiated if you
logged in through the login window. For xterm, this behavior has to be
invoked with the -ls switch on the invocation.
Jonathan
On Dec 28, 2004, at 7:36 PM, Doug McNutt wrote:
At 10:10 -0800 12/28/04, Justin Walker wrote:
AFAIK, this file is not "truly global". No shell that I am aware of
reads this file, and no command-line app knows about it. This file
is used by the Finder, when it invokes a "double-clicked" Aqua app,
to set up an environment in the same way that the shell sets one up
for command-line apps. Also, most (or, at least, many) Aqua apps
don't know about or use environment variables.
This is a copy of my environment.plist file. Note that is has grown
over time to include some variables that I don't even remember putting
there. Some were for testing these very points with the logging lines
I write while in .tcshrc.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DOUG</key>
<string>Douglas P. McNutt</string>
<key>LANG</key>
<string>us_ENG</string>
<key>LC_ALL</key>
<string>C</string>
<key>PATH</key>
<string>/Users/doug/bin:/opt/local/bin:/usr/local/bin:/bin:/sbin:/
usr/bin:/usr/sbin</string>
<key>RCCOUNT</key>
<string>0</string>
<key>SERVER_NAME</key>
<string>Earth</string>
<key>SHELLOG</key>
<string>/Users/doug/logs/shel_log</string>
<key>PROJ</key>
<string>/Volumes/Echo/Projects</string>
<key>BASH_ENV</key>
<string>/Users/doug/.bashrc</string>
<key>ENV</key>
<string>/Users/doug/.shrc</string>
</dict>
</plist>
The plist seems to be read at login-to-Aqua time. If you attempt to
change a variable by editing the plist and then restarting an
application from Finder or from a shell your changes are ignored. A
logout and login (to Aqua) is required. It is more likely read by the
login application than by Finder.
You cannot add items to a factory supplied PATH in a .plist file.
In Terminal (tcsh):
echo $DOUG -> Douglas P. McNutt
echo $PATH -> does find my specials but that may be from old code in
~/.tcshrc
In a BBEdit worksheet:
echo $DOUG -> Douglas P. McNutt
echo $PATH -> comes up the way I set it in the .plist.
In a freshly opened X11 window:
echo $DOUG -> Douglas P. McNutt.
echo $PATH -> adds /usr/X11R6/bin/ to the path in the .plist.
from an external login using telnet from my Linux box:
Is still on my todo list. Someday.
Telnetting to the Linux box from Terminal loses all Mac environment
variables and I'm not surprised.
In AppleScript a "do shell script" request does honor my environment
variables even though it now goes to bash rather than the tcsh I
specify in my Aqua user options.
I didn't check right now but I believe my cron jobs use the SHELLOG
variable successfully. They haven't been changed since Jaguar.
Apache honors the SERVER_NAME given in the plist though I haven't gone
far with that and it's not running now.
--
--> There are 10 kinds of people: those who understand binary, and
those who don't <--
_______________________________________________
Do not post admin requests to the list. They will be ignored.
X11-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
X11-users mailing list (email@hidden)
This email sent to email@hidden