Computing.Net > Forums > Unix > Which shell is running my script?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Which shell is running my script?

Reply to Message Icon

Name: cristian23
Date: September 19, 2007 at 06:40:10 Pacific
OS: UNIX/POSIX
CPU/Ram: 512
Product: xx
Comment:

Hi, I'm trying to find out from within a script which shell is running it, so I can take some decisions based on that. If it's ksh, bash or something else.

The $SHELL variable stores the default user shell, not the current one, and "echo $0" is good only from the command prompt.

Advices much appreciated.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: September 19, 2007 at 09:45:11 Pacific
Reply:

The first tip in this article "Korn Shell Nuances" might be helpful:

http://www.samag.com/documents/s=10...


0

Response Number 2
Name: fpmurphy
Date: September 22, 2007 at 17:16:30 Pacific
Reply:

It really is a bad idea not to write your script to use the POSIX shell.

However if you must try and figure out the invoking shell from within your script you can do so as follows

ps -h -o "%c" -p $$

The -h option (to hide headers) may be problematic on some systems. An alternative
would be:

ps - o "%c" -p $$ | tail -1


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Which shell is running my script?

Running a shell script from cron www.computing.net/answers/unix/running-a-shell-script-from-cron/4091.html

quit running a script www.computing.net/answers/unix/quit-running-a-script-/4464.html

Script in ksh www.computing.net/answers/unix/script-in-ksh/3844.html