[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: simple function causes BASH to exit when -e in effect
From: |
Kevin Layer |
Subject: |
Re: simple function causes BASH to exit when -e in effect |
Date: |
Fri, 22 Dec 2017 10:56:18 -0800 |
The man page says:
The shell does not exit if the command that fails is part of the
command list immediately following a while or until keyword,
part of the test following the if or elif reserved words,
part of any command executed in a && or || list except the
command following the final && or ||, any command in a
pipeline but the last, or if the command's return value is being
inverted with !.
The fact that [ exits with 1 seems to be covered by the above passage for
-e.
On Fri, Dec 22, 2017 at 10:50 AM, DJ Mills <danielmills1@gmail.com> wrote:
>
>
> On Fri, Dec 22, 2017 at 1:39 PM, Kevin Layer <layer@known.net> wrote:
>
>> The bug happens to me on
>> GNU bash, version 4.1.2(2)-release (x86_64-redhat-linux-gnu)
>> and
>> GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin16.4.0)
>>
>> The script is attached, but the function in question is this:
>>
>> function debug1 {
>> [ "$debug" ] && echo "$(date "+%Y-%m-%d %H:%M:%S"): $@"
>> }
>>
>>
> This is expected behavior. When "$debug" is empty, the [ command exits 1.
> That means the && isn't
> run, and the whole function returns with the status of the last run
> command, which is still 1 at this point.
>
> http://mywiki.wooledge.org/BashFAQ/105
>