Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: help with 'rename' function
- X-seq: zsh-users 1595
- From: Zefram <zefram@xxxxxxxxx>
- To: luomat+Lists/Zsh/users@xxxxxxxxxxxxxxx (Timothy J Luoma)
- Subject: Re: help with 'rename' function
- Date: Fri, 12 Jun 1998 10:26:15 +0100 (BST)
- Cc: zsh-users@xxxxxxxxxxxxxxx
- In-reply-to: <199806120816.EAA22173@xxxxxxxxxxxxxxx> from "Timothy J Luoma" at Jun 12, 98 04:15:57 am
Timothy J Luoma wrote:
>You would do
>
> rename *.THIS THIS=THAT
function rename {
emulate zsh
setopt localoptions
integer st=0
local pat old new f
if (( $# < 2 )) || { pat=$argv[$#]; [[ $pat != *\=* ]]; }; then
echo >&2 "Usage: rename <files...> <foo>=<bar>"
return 2
fi
old=${pat%%\=*}
new=${pat#*\=}
for f in $argv[1,-2]; do
if [[ $f != *$old ]]; then
st=1
echo >&2 "$f: does not end with suffix \`$old'"
elif ! mv $f ${f%$old}$new; then
st=1
fi
done
return $st
}
If you use the files module, then this function does not use any external
commands.
-zefram
Messages sorted by:
Reverse Date,
Date,
Thread,
Author