1 # $NetBSD: var-op-shell.mk,v 1.3 2020/11/09 20:39:46 rillig Exp $
3 # Tests for the != variable assignment operator, which runs its right-hand
4 # side through the shell.
6 # The variable OUTPUT gets the output from running the shell command.
7 OUTPUT!= echo "success"'ful'
8 .if ${OUTPUT} != "successful"
12 # Since 2014-08-20, the output of the shell command may be empty.
14 # On 1996-05-29, when the '!=' assignment operator and Cmd_Exec were added,
15 # an empty output produced the error message "Couldn't read shell's output
18 # The error message is still there but reserved for technical errors.
19 # It may be possible to trigger the error message by killing the shell after
20 # reading part of its output.
26 # The output of a shell command that failed is processed nevertheless.
27 # TODO: Make this an error in lint mode.
28 OUTPUT!= echo "failed"; false
29 .if ${OUTPUT} != "failed"
33 # A command with empty output may fail as well.
39 # In the output of the command, each newline is replaced with a space.
40 # Except for the very last one, which is discarded.
41 OUTPUT!= echo "line 1"; echo "line 2"
42 .if ${OUTPUT} != "line 1 line 2"
46 # A failing command in the middle results in the exit status 0, which in the
47 # end means that the whole sequence of commands succeeded.
48 OUTPUT!= echo "before"; false; echo "after"
49 .if ${OUTPUT} != "before after"
53 # NB: The signal number must be numeric since some shells (which ones?) don't
54 # accept symbolic signal names. 14 is typically SIGALRM.
56 # XXX: The number of the signal is not mentioned in the warning since that
57 # would have been difficult to implement; currently the errfmt is a format
58 # string containing a single %s conversion.
59 OUTPUT!= kill -14 $$$$
64 # A nonexistent command produces a non-zero exit status.
65 OUTPUT!= /bin/no/such/command
70 # The output from the shell's stderr is not captured, it just passes through.
71 OUTPUT!= echo "stdout"; echo "stderr" 1>&2
72 .if ${OUTPUT} != "stdout"
76 # The 8 dollar signs end up as 4 dollar signs when expanded. The shell sees
77 # the command "echo '$$$$'". The 4 dollar signs are stored in OUTPUT, and
78 # when that variable is expanded, they expand to 2 dollar signs.
79 OUTPUT!= echo '$$$$$$$$'
80 .if ${OUTPUT} != "\$\$"