1

I want to call the make command from a bash script in a MinGW bash shell. However the script seems to know "make" only when I call the script using source:

build.sh:

#!/bin/bash
make all

Calling source build.sh from the terminal works: The target all is built.

Calling only build.sh from the terminal results in

./build.sh: line 2: make: command not found

Why do I have to source the script to have a working make command?

Aserre
  • 4,916
  • 5
  • 33
  • 56
  • Are you using bash in your terminal as your default shell? – Dominik Jan 16 '22 at 21:12
  • 2
    What does `which make` tell you? – Vroomfondel Jan 17 '22 at 08:43
  • 1
    Use `/usr/bin/make` or better check `which make` and use `$path/make all` – Riz Jan 17 '22 at 09:17
  • Are you using the MSYS2 bash shell, or which shell exactly are you calling this from? Is the location of `make.exe` listed in the `PATH` environment variable (check with `echo $PATH`)? – Brecht Sanders Jan 17 '22 at 11:44
  • Seems like it might be some kind of shell configuration issue. Edit the script to add `echo $PATH` before you invoke make, then source it and run it and see what the difference is. – MadScientist Jan 17 '22 at 16:24
  • I am using Git bash ("%PROGRAMFILES%\git\usr\bin\bash.exe" -i -l) in Windows Terminal 1.10.2714.0) – user17949438 Jan 17 '22 at 17:18
  • which make results in "which: no make in ( ... my whole $PATH ... )", no matter if I call it from the command line or from build.sh (with and without source) – user17949438 Jan 17 '22 at 17:20
  • I've checked $PATH. It is exactly the same when I echo it from the command line, when I echo it from the script, and when I echo it from the sourced script. – user17949438 Jan 17 '22 at 17:28
  • Searching my whole HDD, it turns out that I don't have any executable make.* at all anywhere on my PATH or in any subfolder of %PROGRAMFILES%\git. So, how is it possible that make is a known command in my environment? – user17949438 Jan 17 '22 at 17:41
  • MinGW is old, install Ubuntu on Windows 10 or Windows 11 and try the same script – Christopher Hoffman Jan 19 '22 at 15:12

0 Answers0