Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Each command in Makefile is executed by a separate shell.

What is the reason for this? Why commands aren't executed as in a regular script? I am aware that it is possible to use one shell using .ONESHELL special target.

But what are the reasons for default behavior?

share|improve this question
can you quote an original source, such as where in the manual it is documented that each line is a new shell? – tarabyte Jul 29 '15 at 2:06
@tarabyte gnu.org/software/make/manual/make.html#Execution – Maxim Jul 29 '15 at 6:09

I can't tell you the rationale of the make makers, but one shell per recipe line makes sense to me in that there is only one state to be kept and modified and that's the state in the make process. Also, one fresh shell per line ensures that each line does the same thing every time it is executed. If it always were the same shell recipe lines and even entire recipies might have side effects on each other and the make process has virtually no method of detecting what is desireable and what is not ... let alone controling that behaviour. A shell per line makes every line atomic and program flow is returned to make, which gives a lot more power to make.

share|improve this answer

I suspect the reason is that "make" normally halts if there's an error result. So if you have 3 separate commands, it may be wise to halt immediately if command #1 fails.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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