less -r と less -R の違い

less -r と less -R の違い

less2つのオプションがあります:

-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色の制御文字のみを許可するため、出力には色付きのテキストを含めることができますが、出力を台無しにする可能性のあるその他の書式設定文字を含めることはできません。

関連情報