Project

General

Profile

Bug #5613

odd ls -U behaviour if output is not a terminal

Added by Hans Rosenfeld almost 6 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
-
Start date:
2015-02-13
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage
Gerrit CR:

Description

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
...

Also available in: Atom PDF