问题
This is a continuation of the following question:
Globbing accented files in Bash
I asked it there, but was encouraged to ask a new question.
I have about 20,000 thousand files, many of which need to be renamed. If they have the same prefix, they are numbered sequentially regardless of extension. This isn't my problem, it just explains the options I'm using with the rename
command below.
Problem: Several filenames contain accented characters, which seem to prevent globs from being expanded. The rename
command thus doesn't rename the appropriate files.
I am on macOS 10.14.4, running Bash 5.0.3.
Here is a minimal example:
#! /usr/local/bin/bash
filenamestem="Vvért, Cdeós"
rename -n -X -N 001 -e '$_ = "'"${filenamestem}"'_$N"' "${filenamestem}"*
Here is the output when set -x
is added:
+ filenamestem='Vvért, Cdeós'
+ rename -n -X -N 001 -e '$_ = "Vvért, Cdeós_$N"' 'Vvért, Cdeós*'
'Vvért, Cdeós*' would be renamed to 'Vvért, Cdeós_001'
Here are some of the files in the directory:
'Vvért, Cdeós copy.doc'
'Vvért, Cdeós copy.pdf'
'Vvért, Cdeós-2 copy.docx'
'Vvért, Cdeós-2.docx'
'Vvért, Cdeós.doc'
'Vvért, Cdeós.pdf'
When the filenames lack accents or other diacritics, the command works wonderfully.
I have tried
rename -n -X -N 001 -e '$_ = "'"${filenamestem}"'_$N"' "$(iconv -t UTF-8-MAC <<< "${filenamestem}")"*
according to the solution to the question mentioned above, but receive the same output:
+ filenamestem='Vvért, Cdeós'
++ iconv -t UTF-8-MAC
+ rename -n -X -N 001 -e '$_ = "Vvért, Cdeós_$N"' 'Vvért, Cdeós*'
'Vvért, Cdeós*' would be renamed to 'Vvért, Cdeós_001'
Finally, the files I've been testing on reside on a local disk, which is using APFS. The files I'd ultimately like to rename are on a server, whose file system with which I'm not familiar, in case this is important. In any case, I have the same problem when running these commands on both sets of files.
Would anyone know how to have this work on filenames with diacritics?
来源:https://stackoverflow.com/questions/55642012/globbing-and-renaming-accented-files-in-bash-continued