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

Re: zmv exits from function



On 12/30/23, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Sat, Dec 30, 2023 at 9:43 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>>
>> I'm using zmv to rename files in a directory tree recursively via a
>> 'for' loop which visits each subdirectory.  It works fine if there are
>> files found to rename, but if not, then the entire function crashes back
>> to CL.  How can I persuade zmv to just let the function cycle to the
>> next subdir?
>
> zmv forces zsh emulation which means the nomatch option is in effect,
> and you can't change that without editing the zmv source.
>
> Just run the zmv in a subshell:
>
>   ( zmv '(*).SNT' '$1.eml' )
>   ( zmv '(*).MES' '$1.eml' )

You can also do this:
  { zmv '(*).SNT' '$1.eml' } always { TRY_BLOCK_ERROR=0 }

I have this aliased as
  alias always_continue='always { TRY_BLOCK_ERROR=0 }'
which lets you do the slightly neater
  { zmv '(*).SNT' '$1.eml' } always_continue

-- 
Mikael Magnusson




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