<p><strong>Makefile</strong></p>

<pre><code>all: test dosomething

test:
    @echo "hello"

dosomething:
    @if [ "a" = "a" ]; then\
        echo "world";\
        exit 0;\
    fi
</code></pre>

<p>Running: <code>make</code> will return:</p>

<pre><code>hello
world
</code></pre>

CC BY-SA 4.0
2019-12-31T21:56:11.253Z
2019-12-31T21:56:11.253Z
030
<p>Let's say that I have 2 targets:</p>

<pre><code>test:
    # ...
    @$(MAKE) dosomething
    @echo test
    # ...

dosomething:
    # ...
    @if [ -z "$(SOMETHING)" ]; then exit 0; fi
    @echo dosomething
    # ...
</code></pre>

<p>I would like <code>echo test</code> to execute even if <code>$(SOMETHING)</code> is empty and <code>echo dosomething</code> only if <code>$(SOMETHING)</code> is not empty (which doesn't work with the example, it's still executed).</p>

<p><code>exit 0</code> of course doesn't work here since <code>make</code> ignores non-negative exit in subshells used to execute instructions.</p>

<p>Is there any other way to skip the rest of the target without breaking further execution of <code>test</code> target? I could make the rest a single long instruction of else but wondering if there's a different command I'm maybe missing.</p>

CC BY-SA 4.0
2019-12-31T21:57:05.807Z
Please let me know whether the example is what you are looking for. Could you indicate how the expected output should look like?
030
CC BY-SA 4.0
2019-12-31T23:00:02.920Z
Not quite, I edited my question to be more specific
Destroy666
<bash>
Exit a Makefile target called by parent without throwing an error
Destroy666
# Exit a Makefile target called by parent without throwing an error

(Asked by: username_0 on 2019-12-31)

Let's say that I have 2 targets:
test:
    # ...
    @$(MAKE) dosomething
    @echo test
    # ...

dosomething:
    # ...
    @if [ -z "$(SOMETHING)" ]; then exit 0; fi
    @echo dosomething
    # ...

I would like echo test to execute even if $(SOMETHING) is empty and echo dosomething only if $(SOMETHING) is not empty (which doesn't work with the example, it's still executed).
exit 0 of course doesn't work here since make ignores non-negative exit in subshells used to execute instructions.
Is there any other way to skip the rest of the target without breaking further execution of test target? I could make the rest a single long instruction of else but wondering if there's a different command I'm maybe missing.

**Tags:** bash

> **Comments:**
> **username_1**: Please let me know whether the example is what you are looking for. Could you indicate how the expected output should look like?  
> **username_0**: Not quite, I edited my question to be more specific  

---

## 1 answers

### Answer by username_1 on 2019-12-31. Score: 1

Makefile
all: test dosomething

test:
    @echo "hello"

dosomething:
    @if [ "a" = "a" ]; then\
        echo "world";\
        exit 0;\
    fi

Running: make will return:
hello
world


---

