I wrote the following function to recursively rename files in some subdirectories:
rrename(){ find . -type f -name $1 -execdir mv {} $2 ';' }
This works fine when I call it like this:
rrename '*.md' renamed.md
however, I would rather not need to include the single quotes and call it like this instead:
rrename *.md renamed.md
I tried this but it still does not work:
rrename(){ find . -type f -name "'$1'" -execdir mv {} $2 ';' }
HOw can I fix it?
*.md
; and 2) if you have several files ending with.md
in the same directory they will all be both renamed torenamed.md
(i.e. only one will be kept, the other ones will be lost)rrename
is not syntactically valid in Bash. It's not the function cannot be used, it cannot be defined in the first place. The definition would work in Zsh. Your blatantly unquoted$1
and$2
are wrong in Bash, they can be safely left unquoted in Zsh. Despite thebash
tag, is your shell Zsh?