I'd like to know if a given script is running under Ash, Dash, Bash, ZSH or something else.
The script may or may not have a shebang line, and it can be executed either directly (my-script.sh
) or as an argument to a shell interpreter (sh my-script.sh
).
What's the most straightforward way to find that out?
Edit: After reading the answers below and the duplicate question, I've found this to be the most simple and reliable way to find the name of the shell executing a script under Linux:
show_shell() { basename "$(readlink -f /proc/$$/exe)" ;}