重複上一個字元 (REP)

將上一個列印的字元重複 `n` 次。

  1. 0x1B
    ESC
  2. 0x5B
    [
  3. ____
    n
  4. 0x62
    b

參數 n 必須是大於等於 1 的整數。如果 n 小於 等於 0,則將 n 調整為 1。如果省略 n,則 n 預設為 1。

在 xterm 中,只支援單位元組(小於十進位 256)的字元。在大多數其他 主流終端機中,支援任何字元。

每個重複字元的行為與手動輸入它完全相同。因此,軟換行、邊界等的 行為都與手動輸入該字元時相同。

上一個列印的字元是透過任何方式列印的任何字元。上一個列印的字元不限於 使用者手動輸入的字元。如果不存在之前輸入的字元,此序列 不執行任何動作。

驗證

REP V-1:簡單用法

printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "A"
printf "\033[b"
|AAc_______|

REP V-2:軟換行

cols=$(tput cols)
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[${cols}G"
printf "A"
printf "\033[b"
|_________A|
|Ac________|