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?

  • I always figured it was the system/user default shell, whatever that is. Haven't seen the docs or anything though.
    – Zoredache
    Jul 20, 2015 at 19:51

3 Answers 3


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.

  • 1
    I 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, 2015 at 19:54
  • 2
    @ it is the words “as if” that are important. The spec is about behaviour (semantics), not about implementation. Jul 20, 2015 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
    – lkanab
    Apr 30, 2019 at 13:24
  • 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. Jun 12, 2020 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:

bash: SHELL := bash
    # note: the double dollar-sign is required because Make substitues $variables
    export greeting="¡hola"
    echo "$${greeting}, bash!"

And this is just showing off:

python: SHELL := python3
    greeting = "hello"
    print(f"{greeting}, python!")

So, make python then prints 'hello, python!'.


@Michael (+1) said it all (and gave pointers for the details). Nevertheless I will emphasize a pair of details (please correct me):

  1. make actions uses "sh"

  2. if useful in gnumake we can redefine shell

    SHELL = bash

and use bash tricks.

  1. (in a unix based environment) -- mv, echo are commands (we can use them in any shell) if and for are sh/bash depend.

  2. shells have a different behavior in respect to quotations, (and also globs and var expansions...) and make also has some peculiar behavior about them.

  3. 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)

  • Could you elaborate on and use bash tricks? What exactly are bash tricks? Jun 12, 2020 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.