Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#8993 closed bug (fixed)

garbled ls -l output when piped with less

Reported by: Prasad Owned by: leavengood
Priority: normal Milestone: R1
Component: Applications/Terminal Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

Running "ls -l | less" shows lot of garbled output.

Attaching screenshot.

Attachments (2)

garbled-ls-outut.jpeg (111.7 KB ) - added by Prasad 12 years ago.
0001-bash_profile-set-ls-color-alias-to-auto.patch (1.0 KB ) - added by Prasad 12 years ago.

Download all attachments as: .zip

Change History (12)

by Prasad, 12 years ago

Attachment: garbled-ls-outut.jpeg added

comment:1 by anevilyak, 12 years ago

Component: PreferencesApplications/Terminal
Owner: changed from nobody to jackburton

comment:2 by Prasad, 12 years ago

in the list of default aliases "ls" is aliased as

alias ls="ls --color"

In the source file of ls "src/bin/coreutils/src/ls.c"

1877         case COLOR_OPTION:
1878           {
1879             int i;
1880             if (optarg)
1881               i = XARGMATCH ("--color", optarg, color_args, color_types);
1882             else
1883               /* Using --color with no argument is equivalent to using
1884                  --color=always.  */
1885               i = color_always;
1886 
1887             print_with_color = (i == color_always
1888                                 || (i == color_if_tty
1889                                     && isatty (STDOUT_FILENO)));

Therefore, when ls is used with --color argument, it is always treated as ls --color="always", thus it ignores the isatty(STDOUT_FILENO) call and sets print_with_color = 1

As a result, even though "ls" output is redirected to a file, all the coloring scheme is still applied, resulting garbled characters added into the file.

So the fix is

$ git diff
diff --git a/data/etc/profile b/data/etc/profile
index a654808..e61bbc8 100644
--- a/data/etc/profile
+++ b/data/etc/profile
@@ -24,7 +24,7 @@ export LC_COLLATE=$LC_MESSAGES
 export LC_CTYPE=$LC_MESSAGES
 export LC_MONETARY=$LC_NUMERIC
 
-alias ls="ls --color"
+alias ls="ls --color=auto"
 alias ll="ls -lA"
 alias la="ls -A"
 alias m="more"

comment:3 by Prasad, 12 years ago

patch: 01

comment:4 by Prasad, 12 years ago

Attaching a patch which fixes the problem

comment:5 by diver, 12 years ago

Version: R1/alpha3R1/Development

comment:6 by scottmc, 12 years ago

Also semi-related to this, is track ticket #4494 which has a possible fix for poor default colors for ls --color

comment:7 by leavengood, 12 years ago

Owner: changed from jackburton to leavengood
Status: newin-progress

Taking ownership.

comment:8 by leavengood, 12 years ago

Resolution: fixed
Status: in-progressclosed

Patch applied in hrev44676. Thanks!

comment:9 by diver, 12 years ago

Thanks! This one was annoying.

comment:10 by korli, 12 years ago

As explained in #9044 this kind of customization should go in a specific /etc/profile.d/ script.

Note: See TracTickets for help on using tickets.