Which shell is used in GNU Make files?
It's sh
:
The execution line shall then be executed by a shell as if it were passed as the argument to the system() interface
system()
uses sh
. You can definitely use the keywords of the POSIX Shell Command Language, and any non-keyword commands that you expect to be available on your host platform.
sh
on your system may actually be another name for a different shell (like bash
), in which case you'd have more options available. That sort of makefile won't be portable, though.
As you ask about GNU make specifically, I'll also note that it permits you to specify a different shell to use in the makefile, but that makefile again won't be portable to other implementations of make
. GNU make uses sh
by default, as POSIX specifies.
@Michael (+1) said it all (and gave pointers for the details). Nevertheless I will emphasize a pair of details (please correct me):
make actions uses "sh"
if useful in gnumake we can redefine shell
SHELL = bash
and use bash tricks.
(in a unix based environment) --
mv
,echo
are commands (we can use them in any shell)if
andfor
are sh/bash depend.shells have a different behavior in respect to quotations, (and also globs and var expansions...) and
make
also has some peculiar behavior about them.in windows, etc, together with the installation of gnumake command, it may be useful to install some sort of a Unix surviving kit (sh / bash, some filters, fileutils, and the commands you normally use in make actions)
You should also look at PolyGlot Makefiles, a short note on selecting the shell for particular makefile targets.
Here's selecting bash for a target named bash:
.ONESHELL:
bash: SHELL := bash
bash:
# note: the double dollar-sign is required because Make substitues $variables
export greeting="¡hola"
echo "$${greeting}, bash!"
And this is just showing off:
.ONESHELL:
python: SHELL := python3
python:
greeting = "hello"
print(f"{greeting}, python!")
So, make python
then prints 'hello, python!'.