Setting the SHELL variable in a Makefile works, however Make normally uses /bin/sh
as shell, so minor differences creep in.
I grew fond of adding colors to the makeoutput, but these now come out wrong when changing from sh to bash shell.
Here is a makefile
SHELL=/bin/bash #-o pipefail
LYELLOW ="\\033[1;33m"
NC ="\\033[0m"
demo1:
@ set +o pipefail && echo $(LYELLOW)"I will fail"$(NC) && test 1 -eq 2 | cat
@ echo done
demo2:
@ set -o pipefail && echo $(LYELLOW)"I will fail"$(NC) && test 1 -eq 2 | cat
@ echo done
demo3:
@ set -o pipefail && echo -e $(LYELLOW)"I will fail"$(NC) && test 1 -eq 2 | cat
@ echo done
That by running demo1 and demo2 produces the output:
$ make demo1
\033[1;33mI will fail\033[0m
done
$make demo2
\033[1;33mI will fail\033[0m
make: *** [Makefile:11: demo2] Error 1
that is all very well with using the (outcommented in the Makefile above) global pipefail ala SHELL=/bin/bash -o pipefail
or just by adding perline pipefails ala
set -o pipefail && "some commands>"
But colors are now output correctly anymore (the backslashes now comes out directly to the terminal, colors also being hard to show here, anyway).
The fix for this it to add an -e
on the echo statements using the bash
shell as in the demo3
target, somehow not needed when running sh
.