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

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



On 27 Sep 2018, at 14:20, Vasiliy Ivanov <beelzebubbie.logs@xxxxxxxxx> wrote:
>% ( b=123123; print =$b; print 'ohshi' )
>zsh: 123123 not found
>
>Is it intended behaviour?

That's because of the option nomatch, which is enabled by default and is
documented as follows:

  If a pattern for filename generation has no matches, print an error, instead
  of leaving it unchanged in the argument list. This also applies to file
  expansion of an initial ‘~’ or ‘=’.

The documentation could probably be more explicit — it doesn't just print an
error, it also aborts the current command (and apparently the following ones; i
didn't even realise that).

You can disable it by setting either no_nomatch or null_glob (which both pass
the = pattern through as a literal string, somewhat surprisingly). If you don't
want one of those on permanently (a lot of people would recommend against it for
safety reasons), you can wrap it in an anonymous function or similar:

  () { setopt local_options no_nomatch; echo =123123 }

I don't think there's any way to disable it per-expansion in the vein of the (N)
glob qualifier.

dana



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