15

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?

0

2 Answers 2

6

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.

2

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.