问题
How can you do absolute positioning of output? Very similar to like when Linux first boots and you see the following:
Starting process blah blah blah [ OK ]
回答1:
You can see the code used to produce those [ OK ]
in many Linux distributions in /etc/init.d/functions
$ grep echo_ /etc/init.d/functions
echo_success() {
echo_failure() {
echo_passed() {
echo_warning() {
$
Upon inspection, you will see that those function use ANSI escape sequences.
echo_success() {
[ "$BOOTUP" = "color" ] && $MOVE_TO_COL
...
return 0
}
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
回答2:
You can use "tput cup 10 10" to move the cursor to desired location. In this case 10th column and 10th row. Check out the tput's man page.
来源:https://stackoverflow.com/questions/20381937/bash-text-absolute-positioning