I'd like to simplify the example, but any further simplification removes the problem … I already stripped my script down to this:
#!/bin/sh
echo "$1" | sed 's/[^[:alnum:]]//g'
This does what I expect it to do when called directly, but not as part of a find -exec
:
$ cp "Motörhead "{1,2}
$ ./foo.sh M*1
Motörhead1
$ ./foo.sh M*2
Motörhead2
$ find . -name "M*" -exec ./foo.sh {} \;
Motorhead1
Motörhead2
Everything is fine when called directly, but as part of the -exec
command, the Umlaut gets messed up, at least sometimes. The difference? Motörhead 1
was created by the finder, while Motörhead 2
was created by the shell. It's like find
has a problem to detect the character encoding of the file names created by the finder.
- If I replace the second script line with
name="Motörhead"
, the problem is gone - Reproducable on
apfs
andexfat
file system andafp
mount - I'm on MacOS Catalina in Terminal.app with zsh
locale
isde_DE.UTF-8
ö
comes out aso
with thefind
command.Motörhead 3
in the Finder, this will sort beforeMotörhead 2
created in the shell in the output ofls -l
. Piping the output ofprintf '%s\n' M*
tood -h
shows that theö
is the same in all three filenames (b6c3
).ö
, as composing characters. That is as two characters:composing "
, followed byo
. Probably this does not apply to the Unix layer. Can you do a test to see if this is true?ls M* | tr o x
gives me something likeMxtẍrhead
, so botho
are replaced, while the ` ̈` is now attached to thex
. It seems, they worked around the problem in many cases, but failed to cover all, resulting in strange inconsistencies.