2014-03-12 91 views
0

所以我創建了這個文件,目前我正在bash shell中運行它,它列出的很好,但是每個結果都放在它自己的行上。我想知道我將如何製作相同的程序,但讓它將結果橫向放置,一個接一個。你如何把結果放在一條線上? (在bash中)

x=0;while [ $x -le 256 ] 
do 
t=$(tput sgr 0);r=$(tput setaf $x);echo "${r} $x ${t}";((x=$x+1)) 
done 
+0

在列中還是在行中?你說的是單行,但後來_rows_ – rpax

+0

我不確定這是否與Vim相關的問題。如果使用的編輯器對問題或答案沒有影響,最好刪除該標籤。 –

+0

請記住:'more'和'col'只能打印純文本 – gallabytes

回答

0

我所理解的,u需要像這樣:

x=0;while [ $x -le 256 ] 
do 
t=$(tput sgr 0);r=$(tput setaf $x);echo -n "${r} $x ${t}";((x=$x+1)) 
done 

ü忘記用回聲-n(沒有新行)

格式版本的列:

#!/bin/bash 

t=$(tput sgr 0) 
for x in {0..255}; do 
    printf "%s%4s${t}" "$(tput setaf $x)" $x 
    if [ $((x % 15)) -eq 0 ]; then echo; fi; 
done 
0

嘗試less -rless -R

less手冊頁:

-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 tries to keep track of the screen appearance where possible. 
     This works only if the input consists of normal text and possibly some 
     ANSI "color" escape sequences, which are sequences of the form: 

      ESC [ ... m 

     where the "..." is zero or more characters other than "m". For the 
     purpose of keeping track of screen appearance, all control characters 
     and all 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. 
0

命令echo,自動添加一個新的生產線。 如果要在一行中打印輸出,請使用printf命令。

要改變顏色,你可以使用\ E,是這樣的:

echo -e "\e0;31m Your text" 

這條線將打印文本紅色。 您可以更改編號31.

相關問題