Janis Papanagnou <
janis_pap...@hotmail.com> writes:
> On 06.02.2023 05:41, Keith Thompson wrote:
>> Zhao-hui Liu <
lll...@gmail.com> writes:
>>> On Monday, February 6, 2023 at 9:31:14 AM UTC+8, Keith Thompson wrote:
>>>> I'd suggest `cd /etc/rsyslog.d || exit 1`, so the script indicates that
>>>> it failed.
>>>
>>> `command || exit' is sufficient to indicate script failure, and better
>>> than `command || exit 1', because the latter always returns 1 if
>>> fails, while the former reflects the exit code of command.
>>
>> Good point.
>>
>> I had forgotten that the built-in `exit` command with no arguments uses
>> the exit status of the last command executed. (POSIX specifies this.)
>>
>> If you prefer to be more explicit (as I do), you can use `command || exit $?`.
>
> Notwithstanding there's a point in explicitly specifying an exit code
> (i.e. different from $?), depending on where you come from.
>
> If you think your scripts from a systems perspective you may not be
> interested in the technical reason that $? (or a plain exit) provides;
> you may want to get information from the software process as a whole,
> effectively a process oriented abstraction layer. And the concrete
> command's $? would go into a log file for technical debugging where
> it matters.
Agreed. If all I care about is that the script should die with a