Today, I was doing some command-line stuff and then this happened:

ls --help|less
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
ESC]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#ls-aESC\ESC[1m-a, --allESC[0mESC]8;;ESC\
do not ignore entries starting with .
ESC]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#ls-AESC\ESC[1m-A, --almost-allESC[0mESC]8;;ESC\
do not list implied . and ..
ESC]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#ls--authorESC\ESC[1m--authorESC[0mESC]8;;ESC\

It’s rendering ls --help with control characters. When I do ls --help|less --raw-control-chars it doesn’t show the control characters, and it looks all neat and pretty. Isn’t this the opposite of how it’s supposed to work?!

Is --raw-control-chars a toggle and some config is causing less to show control characters when I invoke it with no options? If so, where can I find this config and stop this?

This has absolutely no bearing on my work and my life in general except for the fact that I’ll go absolutely batshit trying to figure this out, because that’s how my brain is. So far, all of my web searches just confirm that less shouldn’t be working this way, but they don’t give me any way to fix it. Please help me, Lemmy!!!

  • thingsiplay@lemmy.ml
    link
    fedilink
    arrow-up
    1
    ·
    8 days ago

    /usr/bin/ls --color=never --help | /usr/bin/less and /usr/bin/ls --color=never --help > ~/Desktop/lshelp.txt produces and contains the same characters, BTW. This happens in Bash and Zsh, using Kitty and Konsole terminals. So its not an issue with less, the shell or terminal. Meaning it might be an issue with ls itself. I have “ls (GNU coreutils) 9.11” from ls --version.

    Ah ls has an option for this: -q, --hide-control-chars But ls -q --color=never --help | less seem not to hide anything, maybe because --help is in use. I can put strings in between, it would only hide control characters, not the normal sequence for other stuff \ls -q --color=none --help | strings | less

    Looks like an issue with ls. I feel helpless.

    • esa@discuss.tchncs.de
      link
      fedilink
      arrow-up
      2
      ·
      7 days ago

      -q controls output for filenames. From ls.c:

      /* True means output nongraphic chars in file names as '?'.
         (-q, --hide-control-chars)
         qmark_funny_chars and the quoting style (-Q, --quoting-style=WORD) are
         independent.  The algorithm is: first, obey the quoting style to get a
         string representing the file name;  then, if qmark_funny_chars is set,
         replace all nonprintable chars in that string with '?'.  It's necessary
         to replace nonprintable chars even in quoted strings, because we don't
         want to mess up the terminal if control chars get sent to it, and some
         quoting methods pass through control chars as-is.  */
      static bool qmark_funny_chars;