#8993: garbled ls -l output when piped with less -------------------------------------+------------------------ Reporter: Prasad | Owner: jackburton Type: bug | Status: new Priority: normal | Milestone: R1 Component: Applications/Terminal | Version: R1/alpha3 Resolution: | Keywords: Blocked By: | Blocking: Has a Patch: 0 | Platform: All -------------------------------------+------------------------ Comment (by Prasad): 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" }}} -- Ticket URL: <http://dev.haiku-os.org/ticket/8993#comment:2> Haiku <http://dev.haiku-os.org> Haiku - the operating system.