Ok, so I can write a shell script with bash, sh, or zsh in mind etc. And I can put a hashbang at the top of the file like so:

#!/usr/bin/env bash

which will tell the kernel which interpreter to use to execute the file.

However, I just realized, I don't know how to tell the machine which interpreter to use at the command line.

e.g., if I write:

$ foo bar baz

at the command line, how do I know what interpreter is being used to interpret that command? How can I tell the computer to use a particular interpreter?

Hopefully the question is clear.

  • mmm, this question is more simply worded - TBH I didn't even know if the command line commands were also interpreted by bash/zsh etc...that was just an educated guess – Alexander Mills Dec 20 '16 at 4:42

To get your login shell, which is most likely the shell you're currently running, unless you have deliberately chosen a different shell (e.g., by choosing a shell other than your login shell in your terminal emulator's preferences, or by explicitly invoking a shell at login time, such as with ssh remote-host /path/to/shell):

echo $SHELL

To use a different shell:

exec /path/to/shell


exec /bin/bash
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.