[oclug] Starting an X Windows term
Joe Burpee
jeb at burkby.com
Wed Aug 29 11:11:47 EDT 2001
On 01/08/29 02:02:50, Gilles J. Seguin wrote:
> Joe Burpee wrote:
> > On 01/08/28 21:30:53, Gilles J. Seguin wrote:
> > > ~/.bashrc by default is not source as a personal file if shell is
> > > interactive.
> > Really? News to me. Cf man bash.
>
> When bash is invoked as an interactive login shell, or as
> a non-interactive shell with the --login option, it first
> reads and executes commands from the file /etc/profile, if
> that file exists. After reading that file, it looks for
> ~/.bash_profile, ~/.bash_login, and ~/.profile, in that
OK. I was really thinking of the 2nd para after that:
"When an interactive shell that is not a login shell is
started, bash reads and executes commands from ~/.bashrc,
if that file exists. This may be inhibited by using the ..."
My point was that the question is really login-vs-non-login rather
than interactive-vs-noninteractive, but I guess that's not entirely
true. This stuff always makes my head ache; then of course there's
bash-vs-sh, posix, etc., etc. 8-[
> ~ $ su -
> Password:
> ~ # cat >> .bashrc
> echo "SHLVL is:$SHLVL"
> ^D
> ~ # echo $SHLVL
> 1
> ~ # exit
> ~ $ su -
> Password:
> SHLVL is:1
> ~ #
>
> OK, gets it
>
> Which test are you suggesting.
Now you've got me. I guess it depends on what you want to do. To some
extent I avoid this test by keeping login-type stuff out of bashrc.
(Similarly, IMO aliases do not belong in profile.d/, but I guess I'm
fussy; anyway it just doesn't make practical sense to keep on sourcing
all that stuff.)
An alternative test for a login shell could be [ -z "${0##-*}" ] or
`case "$0" in -*) ...'; however it's uglier, and basically equivalent to
the SHLVL test.
For things like Patrick's problem /tmp/.X*-lock is relevant. There are
also other X-related situations where $DISPLAY is not enough. E.g. I
sometimes want to know if a script has been invoked from a gui app like
nedit or gvim, vs a console app (vim, mutt, etc.) under an "xterm". So
I look at $TERM, which seems to work.
/etc/bashrc also checks $TERM. (I notice it misses TERM=rxvt.) But
then I also want to know whether it's the *first* xterm started under
xinit.
The login question looks a bit like the "first xterm" question? You
don't really want to know whether you're in a login shell; you probably
want to know whether you're in the *first* (login) shell after init has
just wrapped up a runlevel change (and not to runlevel 5). I don't
think init exports anything in the environment to tell you this. But
there are easy ways to do it: e.g. touch&rm in rc.local and profile.
And there's always the source code.
Sorry for the non-answer Gilles. I guess I'm asking slightly different
questions from the one you were asking.
Joe
More information about the OCLUG
mailing list