odd ls -U behaviour if output is not a terminal
In a script I'm trying to do the following:
$ cd /usr/include $ ls -U *.h | sed ...
The ls command alone works as expected, giving an unsorted list of files that match the expression. When output is redirected into a file or piped into another tool, it's all garbled and makes no sense:
$ cd /usr/include $ ls -U *.h | cat )u 3u Eu Uu gu yu �u �u �u �u �u �u �u �u v v ,v
This happens with /usr/bin/ls and /usr/xpg4/bin/ls, but not with /usr/gnu/bin/ls or /usr/ucb/ls.
It also works when invoked without a list of files:
$ cd /usr/include $ ls -U | cat sdp.h sha2.h xlocale.h stdint.h pr29.h ...