[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: a 'who called me?' variable?



* Dan Berdine (db002i@mail.rochester.edu) [010719 09:11]:
> Is there an environment variable in bash that can be used to tell where 
> bash is running from?  For example, is there a variable I can test in 
> my .bashrc to tell whether I am running remotly, from a tty, from 
> konsole, an xterm, etc.?  I'v looked at the Advanced Scripting HOWTO, 
> but the only thing that looked promising was "$BASH_ENV" which seems to 
> be empty.

Indeed, $BASH_ENV will be empty unless you set it to something
otherwise. AFAICT, the only use this would have in your situation is
to set a result in, not to test the value of. i.e., something like:

if (I'm in an xterm)
  BASH_ENV=~/.bash-xterm
if (I'm at the console)
  BASH_ENV=~/.bash-console
  :
  :
  etc.
export BASH_ENV
exec bash

and, of course, do something to prevent infinite loops. It still feels
a little sloppy to me, and I'd rather see something like sourcing the
appropriate environment files rather than exporting BASH_ENV and exec
bash.

If you want to know what tty you're coming in on, check the $TTY
variable. You can use this to deduce if you're on the console very
easily, and depending on your setups, may be able to distinguish
between an xterm or another network connection. You can also look for
the existence of SSH_TTY in the environment, which should be present
only in an ssh session (or child thereof).

I'm not sure exactly what you're trying to do, but HTH.

Vineet

Attachment: pgpLUP286QpSZ.pgp
Description: PGP signature


Reply to: