Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zmv exits from function
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' )
Also make sure that you don't have the errr_exit or err_return setopts
in effect or the loop will break even with the subshells.
Alternately you could test whether the pattern matches any files
before calling zmv in the first place.
Arguably zmv could use null_glob. Thoughts from -workers?
diff --git a/Functions/Misc/zmv b/Functions/Misc/zmv
index 269fe5ba5..51c8ad3ab 100644
--- a/Functions/Misc/zmv
+++ b/Functions/Misc/zmv
@@ -236,12 +236,14 @@ if [[ $pat = (#b)(*)\((\*\*##/)\)(*) ]]; then
else
fpat=$pat
fi
-files=(${~fpat})
+files=(${~fpat}(#qN))
[[ -n $hasglobqual ]] && pat=$opat
errs=()
+[[ -n $files ]] || errs=( "no files matched \`$fpat'" )
+
for f in $files; do
if [[ $pat = (#b)(*)\(\*\*##/\)(*) ]]; then
# This looks like a recursive glob. This isn't good enough,
Messages sorted by:
Reverse Date,
Date,
Thread,
Author