File: m4.info, Node: Sysval, Next: Mkstemp, Prev: Esyscmd, Up: Shell commands 13.4 Exit status ================ To see whether a shell command succeeded, use ‘sysval’: -- Builtin: sysval Expands to the exit status of the last shell command run with ‘syscmd’ or ‘esyscmd’. Expands to 0 if no command has been run yet. sysval ⇒0 syscmd(`false') ⇒ ifelse(sysval, `0', `zero', `non-zero') ⇒non-zero syscmd(`exit 2') ⇒ sysval ⇒2 syscmd(`true') ⇒ sysval ⇒0 esyscmd(`false') ⇒ ifelse(sysval, `0', `zero', `non-zero') ⇒non-zero esyscmd(`echo dnl && exit 127') ⇒ sysval ⇒127 esyscmd(`true') ⇒ sysval ⇒0 ‘sysval’ results in 127 if there was a problem executing the command, for example, if the system-imposed argument length is exceeded, or if there were not enough resources to fork. It is not possible to distinguish between failed execution and successful execution that had an exit status of 127, unless there was output from the child process. On UNIX platforms, where it is possible to detect when command execution is terminated by a signal, rather than a normal exit, the result is the signal number shifted left by eight bits. dnl This test assumes kill is a shell builtin, and that signals are dnl recognizable. ifdef(`__unix__', , `errprint(` skipping: syscmd does not have unix semantics ')m4exit(`77')')dnl changequote(`[', `]') ⇒ syscmd([{ /bin/sh -c 'kill -9 $$'; } 2>/dev/null; st=$?; test $st = 137 || test $st = 265]) ⇒ ifelse(sysval, [0], , [errprint([ skipping: shell does not send signal 9 ])m4exit([77])])dnl syscmd([kill -9 $$]) ⇒ sysval ⇒2304 syscmd() ⇒ sysval ⇒0 esyscmd([kill -9 $$]) ⇒ sysval ⇒2304