Skip to main content
5 of 5
edited tags
muru
  • 77.9k
  • 16
  • 212
  • 317

Is the $SHELL environment variable only for interactive shells?

I see two possible uses for the SHELL environment variable:

  • It can be used to specify the interactive shell the user wants to use, and/or
  • it can be used by processes to execute other commands with, replacing the command in the usual /bin/sh -c "..." idiom.

If it were only used for the former, it could be something very weird (e.g. ipython), if it shall also be used for the latter, it needs to provide a basic form of POSIX compatibility, e.g. understand the -c parameter and keep the environment intact (which is surprisingly tricky).

The POSIX standard is not very explicit here, it just writes.

This variable shall represent a pathname of the user's preferred command language interpreter. If this interpreter does not conform to the Shell Command Language in the Shell and Utilities volume of IEEE Std 1003.1-2001, Chapter 2, Shell Command Language, utilities may behave differently from those described in IEEE Std 1003.1-2001.

Is the second use actually common and/or valid, and hence something to worry about if I set SHELL to something strange?

Joachim Breitner
  • 1.4k
  • 4
  • 17
  • 25