I've seen things like echo
, mv
, if
, for
, in makefile rules. Some kind of shell commands seem to be recognized. Is this bash? How can I figure out which shell is being used and full list of keywords available to me?

- 4,296
-
I always figured it was the system/user default shell, whatever that is. Haven't seen the docs or anything though. – Zoredache Jul 20 '15 at 19:51
3 Answers
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.

- 76,565
-
1I just tested, and it appears that under GNU make, if the command contains no shell metacharacters, it's executed directly, with no shell at all! – Celada Jul 20 '15 at 19:54
-
2@ it is the words “as if” that are important. The spec is about behaviour (semantics), not about implementation. – ctrl-alt-delor Jul 20 '15 at 20:38
-
A comment only for running GoW make on Windows:
- The default SHELL in windows is usually cmd.exe
- In Windows SHELL environment variable might be set outside makefile thus altering the makefile behavior
- It is recommended to add "SHELL = cmd.exe" or similar in the beginning of makefile to force a known shell syntax for the execution of the makefile
-
Hey Michael, what exactly is that documentation that you've linked for
sh
? When talking about Linux stuff, it is very common for me to see somebody linking a doc and I do not understand what exactly is that documentation. Is it official documentation for make, for sh, or else? I'm trying to understand what exactly I'm reading there. – Rafael Eyng Jun 12 '20 at 16:36
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!'.

- 171
@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)

- 12,170
- 1
- 23
- 45
-
Could you elaborate on
and use bash tricks
? What exactly are bash tricks? – Rafael Eyng Jun 12 '20 at 16:38