Re: a 'who called me?' variable?
D-Man wrote:
>
> On Thu, Jul 19, 2001 at 11:51:06AM -0400, Daniel Patrick Berdine wrote:
> | 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.
>
> Based on your examples there, $TERM might be helpful. For example in
> my .cshrc on the school's Solaris box I have
>
> if ( "$TERM" == "linux" )
> bash && exit
> end
>
> so when I login from my linux box (console) I automatically get bash
> and I don't have to exit csh after I exit from bash.
you can check the $PPID (pid of parent ) and try to figure out what
exactly it is. e.g. when I run bash from tcsh:
jojda:~>bash
bash-2.05$ ps ax|grep $PPID
9277 pts/4 S 0:00 -tcsh
9313 pts/4 S 0:00 grep 9277
bash-2.05$ echo $PPID
9277
bash-2.05$
following script might give you an idea. note that parent is shell if
run in xterm, from sshd etc. so we are interested who parent's parent
is.
#!/bin/bash
export PPPID=`ps alx | \
sed -e 's/ */ /g' | \
cut -d ' ' -f3,4 | \
grep ^$PPID | \
cut -d ' ' -f 2`
echo "PPPID [$PPPID]"
export PPPNAME=`ps ax | \
grep "^ $PPPID " | \
sed -e 's/ */ /g' | \
sed -e 's/^ *//' | \
cut -d ' ' -f 5`
echo "PPPNAME [$PPPNAME]"
# EOF
there are probably better ways to do this...
erik
Reply to: