Sample Header Ad - 728x90

Pasting UTF-8 into Terminal (zsh) does something weird

-1 votes
1 answer
529 views
***Is there an environmental setting that makes pasting text into Terminal work differently from typing it in directly?*** I reported this as a bug, but maybe there's some environmental setting.  After the first failure, I put the command in a script to send them as a demo, but it worked when I ran the script. The command is echo "ΕΡΤΥΙΟΚΗΑΖΧΒΝΜ" | tr [:upper:] [:lower:] The string is Greek letters typed with the keyboard set to Greek.  Behavior is the same whether I use the keys and fingers or the Keyboard Viewer and mouse. locale is en_US.UTF-8 and TextEdit is set to always use UTF-8. I put the command in TextEdit, copied it to clipboard, and pasted into Terminal (with stdin containing the Greek string). Result: zsh: no matches found: [:upper:] If I swap the classes, I get zsh: no matches found: [:lower:] If I save the file from TextEdit, give it a chmod 700, and run it, it does what it should, no error message. If I change the command to convert Greek to Latin with echo "ΕΡΤΥΙΟΚΗΑΖΧΒΝΜ" | tr "ΕΡΤΥΙΟΚΗΑΖΧΒΝΜ" "EPTYIOKHAZXBNM" (instead of using classes), then it works pasted or in script. If I type echo "" | od -xc and paste the Greek between the quote marks, I see that the characters are not ASCII. So Paste from clipboard must be doing something **other than** changing the characters. NOTES: (1) the tr command fails **only** when pasted and it contains neither = nor ?, so escaping those is not a solution, and this is this is not a duplicate of https://apple.stackexchange.com/questions/254014/zsh-no-matches-found (2) It's plausible that zsh might treat [:xxx:] differently from bash, but what we have here is zsh/Terminal treating pasted text differently from typed in text.
Asked by WGroleau (5370 rep)
Mar 6, 2022, 06:41 PM
Last activity: Mar 7, 2022, 12:28 AM