Make – Which Shell is Used in GNU Make Files?

make

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?

Best Answer

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.

Related Question