Skip to main content
1 of 5
Joachim Breitner
  • 1.4k
  • 4
  • 17
  • 25

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.

It seems that make uses $SHELL -c "...", while for example python’s os.system always uses /bin/sh.

Which of these uses of SHELL are “correct” (for whatever that means)?

Joachim Breitner
  • 1.4k
  • 4
  • 17
  • 25