Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: `=' expansion causes script/subshell to exit, bug?



On Thu, Sep 27, 2018 at 9:20 PM, Vasiliy Ivanov
<beelzebubbie.logs@xxxxxxxxx> wrote:
> Hello. Recently I've seen that line like
>
> [[ -x =somebinary ]] || cmd
>
> causes script to exit unexpectedly with message like «/path/to/script:$line: =somebinary not found»,
> instead of invoking || cmd and continue executing
>
> some simple tests:
>
> % ( [[ -x =123123 ]] || { print 'ohshi'; exit 2 } )
> zsh: 123123 not found <exit code 1>
>
> % ( b=123123; print =$b; print 'ohshi' )                                                  ↑
> zsh: 123123 not found
>
> Is it intended behaviour?
>
> % zsh --version
> zsh 5.6.2 (x86_64-pc-linux-gnu)

If you don't want to change any options, you can also use this
construct to avoid exiting without a subshell,

% { [[ -x =somebinary ]] } always { TRY_BLOCK_ERROR=0 } || echo hey
zsh: somebinary not found
hey

I also have this in my .zshrc
alias always_continue='always { TRY_BLOCK_ERROR=0 }'
so I can do just
% { [[ -x =somebinary ]] } always_continue || echo hey
zsh: somebinary not found
hey

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author