stty: : Not a typewriter (really ksh $ENV file)
Bob Lied
lied at cbnewsc.att.com
Sat Mar 9 01:46:44 AEST 1991
In answer to the question of how to avoid interactive stuff in
a ksh $ENV file, especially for things like editor escapes,
there are two common solutions that I know of:
1. The $- variable lists the flags that are set by ksh. If ksh
is invoked interactively (which I believe translates to input and
output are ttys), then the -i flag is set. So, one way to avoid
things that write to the terminal for non-interactive use is
something like this inside the $ENV file:
case "$-" in
*i*) # stty, reset prompts, alias cd, etc ;;
*) # functions and aliases that always export
esac
2. To avoid having the $ENV file sourced at all, there is a trick
that comes from page 78 of "The Kornshell Command and Programming
"Language". Instead of setting ENV directly, you set a secondary
variable and use a side effect of evaluation (ENV is always re-evaluated
at shell startup). So, in the .profile, you set up something like:
export ENVFILE=~/.kshrc
export ENV='${ENVFILE[(_$-=0)+(_=1)-_${-%%*i*}]}'
Note that the last part of this is the same as above: checking $-
to see if the -i flag is set. The rest of the gobbledygood evaluates
to 0 or 1; if it's zero, ENV == ENVFILE, but if it's one, ENV=''.
No one said it had to be obvious.
Bob Lied att!ihlpf!lied
More information about the Comp.sys.3b1
mailing list