How to know which is the parent shell?
Hi!
I work on a netwerk, with the home directory mounted as NFS. I usually work on ZSH but since some of the computers dont have it, and I occasionally need to ssh to it, my shell is BASH, and .bashrc calls a zsh. I want to know, if there is a way to check which shell is running currently? I mean, which shell is running the shell script? This is what I want: Code:
$ cat ./script |
echo $SHELL
|
neh... echo $SHELL is giving me the default shell, bash that is
|
you're right, try with:
echo $shell |
echo $0
should do the trick... but from the command line only. In a script it returns the name of the script itself. |
Minor nit: the "$SHELL" variable isnt set by default by all shells (Ksh, IIRC) and it's not always a readonly variable. Shells have quirks and checking differences is one way to test: for a simple Bash vs Zsh you could work with some nested stuff Bash can't do. Another (more generic and compatible) way could be to look at the process itself:
Code:
shellname() { i=`readlink -f /proc/$$/exe`; case "$i" in */bash) echo "$i";; *) echo "Booh, hiss!";; esac; } [edit] Looking at the title of the thread "How to know which is the parent shell" Ash, Bash and Ksh (but not Jsh) support $PPID. If there's no Parent PID or if it's not readonly you could: Code:
_PPID=`/bin/ps -eopid,ppid|grep "^$$"|awk '{print $2}'`; readlink -f /proc/"$_PPID"/exe |
Thanks. I unfortunately unsubscribed this thread somehow so couldn't read all the answers (duh).
Anyway, seems like "echo $0" tells the current shell. Also, I found something like shellname() in /etc/profile of Suse9.3 Code:
if test -f /proc/mounts ; then _PPID=`/bin/ps -eopid,ppid|grep "^$$"|awk '{print $2}'`; readlink -f /proc/"$_PPID"/exe tells me the parent shell, which actually I was asking. Thanks :) |
All times are GMT -5. The time now is 04:46 PM. |