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
apfsandexfatfile system andafpmount - I'm on MacOS Catalina in Terminal.app with zsh
localeisde_DE.UTF-8