
On Wed, 18 Mar 2020 15:21:54 +1300, Peter Reutemann wrote:
https://blog.balthazar-rouberol.com/text-processing-in-the-shell
Text processing is useful, but it is also prone to some pitfalls. Watch out for locale settings. As the grep(1) man page <http://man7.org/linux/man-pages/man1/grep.1.html> points out, you might expect that writing “[a-d]” is equivalent to “[abcd]”, but it might actually give you “[aAbBcCdD]” instead. Doing export LC_ALL=C turns off all locale handling in the current shell. Also watch out for special characters in filenames. What if any of the filenames returned by the «filter» in “for file in $(«filter»); do «action» done” contains spaces or other funnies? By default, the shell separates strings into words at space, tab and newline characters. The characters it uses are the value of the “IFS” special shell variable. Spaces are very common in filenames these days; you can avoid the shell tripping over these with an assignment like IFS=$'\n' but this still leaves newlines as a potential problem. If you can be sure these will never occur in filenames, you’re fine. Otherwise, slightly more elaborate measures must be taken.