less -r과 less -R의 차이점

less -r과 less -R의 차이점

less두 가지 옵션이 있습니다:

-r또는--raw-control-chars

"원시" 제어 문자가 표시됩니다.

-R또는--RAW-CONTROL-CHARS

와 비슷 -r하지만 ANSI "색상" 이스케이프 시퀀스만 "원시" 형식으로 출력됩니다.

이는 색상 제어 문자만 있을 때 동일하다는 것을 의미합니까? 내 출력은 ^O에 파이핑할 때는 있지만 less -R에 파이핑할 때는 그렇지 않습니다 less -r. 여기서 무슨 일이 일어나고 있는 걸까요?

답변1

맨페이지에 따르면:

    -r or --raw-control-chars
          Causes "raw" control characters to be displayed.  The default is to display control characters using the
          caret  notation; for example, a control-A (octal 001) is displayed as "^A".  Warning: when the -r option
          is used, less cannot keep track of the actual appearance of the screen (since this depends  on  how  the
          screen  responds to each type of control character).  Thus, various display problems may result, such as
          long lines being split in the wrong place.

   -R or --RAW-CONTROL-CHARS
          Like -r, but only ANSI "color" escape sequences are output in "raw" form.  Unlike -r, the screen appear‐
          ance is maintained correctly in most cases.  ANSI "color" escape sequences are sequences of the form:

               ESC [ ... m

          where  the  "..."  is  zero  or  more color specification characters For the purpose of keeping track of
          screen appearance, ANSI color escape sequences are assumed to not move the cursor.  You  can  make  less
          think  that  characters  other  than  "m" can end ANSI color escape sequences by setting the environment
          variable LESSANSIENDCHARS to the list of characters which can end a color escape sequence.  And you  can
          make  less  think  that  characters other than the standard ones may appear between the ESC and the m by
          setting the environment variable LESSANSIMIDCHARS to the list of characters which can appear.

분명히 less기본적으로 ANSI 이스케이프 코드를 이스케이프하여 대신 캐럿(^)과 코드를 표시합니다. -r는 이러한 문자를 이스케이프하지 않으므로 입력에 임의의 이진 데이터가 포함되어 있으면 ANSI 제어 문자의 결과로 콘솔이 의도하지 않은 횡설수설을 출력할 수 있습니다. (그래서 less이러한 문자 자체를 처리하지 않으면 화면이 어떻게 보이는지 알 수 없습니다.) -R색상 제어 문자만 허용하므로 출력에는 색상이 있는 텍스트가 포함될 수 있지만 출력을 엉망으로 만들 수 있는 다른 서식 지정 문자는 포함될 수 없습니다.

관련 정보