ENV file in ksh: is this smart? legal?
Jerry Peek
jdpeek at rodan.acs.syr.edu
Thu Aug 31 03:10:22 AEST 1989
Two questions about things in ksh that don't seem to be answered in TFM.
We've got ksh Version 06/03/86a on a Gould NP1, UTX/32 (BSD-like).
[This is a re-post of a message that didn't get out before, I think.
Our news posting was set up wrong. Sorry if you've seen this.]
#1. I want it my ENV file to act like the ".cshrc" file in csh --
to be read anytime a new, interactive shell starts.
So, I have my ENV variable set this way in .profile:
ENV='$HOME/.kshrc'; export ENV
The filename is in single-quotes. That way, when I run the 'su'
command to start a shell on another account, the ksh on *that* account
will read the .kshrc file for *that* account's $HOME. (If I'd used
double-quotes, the *same* .kshrc file would be read for *all* accounts.)
So now, each time I start a shell, it reads that account's $HOME/.kshrc.
Anybody see problems, or know another way to make this work?
#2. The next problem I have with ENV files -- if their name is stored
in the environment (export ENV) -- is that Korn shell script files
(shell programs) read them too. I have some stuff in my ENV file that
screws up shell scripts.
Here's how I fixed the problem. I put this at the start of my ENV file:
case "$-" in
*i*) ;; # IF SHELL IS INTERACTIVE, READ THIS FILE
*) return ;; # ELSE, EXIT AND DON'T READ IT
esac
It works. For non-interactive shells, the ENV file isn't read --
and the rest of the shell program runs just fine, like I want.
The problem is, TFM doesn't seem to say whether that's legal. It says:
- If return is invoked while not in a function or a script,
then it is the same as an exit .
- exit n Causes the shell to exit with the exit status specified by n.
The first one says that return inside a script is not the same as exit,
but it doesn't say *how* it's different. (Is an 'ENV' file a "script?")
Anyhow, am I doing anything that I'll regret? :-)
Thanks...
--Jerry Peek; Syracuse University Academic Computing Services; Syracuse, NY
jdpeek at rodan.acs.syr.edu///jdpeek at sunris.bitnet///GEnie: J.PEEK1
+1 315 443-3995
More information about the Comp.unix.questions
mailing list