[opensuse] BASH - howto make output stay in one place on screen?
Listmates, In BASH, how can I make the output of several commands all start from the same spot on the screen? In c we used to have all these nice libraries that gave control over X,Y screen output. (IIRC we were actually manipulating the video buffer) But in bash, there doesn't seem to be any way to do this. For example, if I have a simple counter and I want to see the numbers increasing without scrolling a line for every number output, I ended up having to do this (just paste it into the command line): echo -en "\n\tThe count stands at: "; for ((i=1;i<=120;i++)); do mstrlen=${#i}; echo -en "$i"; sleep .1; for ((j=0;j<$mstrlen;j++)); do echo -en "\b"; done; done; echo -e "\n" Surely there is an easier way. What say the bash gurus?? -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
David C. Rankin wrote:
Listmates,
In BASH, how can I make the output of several commands all start from the same spot on the screen?
ANSI control characters. /Per -- Per Jessen, Zürich (5.2°C) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Per Jessen wrote:
David C. Rankin wrote:
Listmates,
In BASH, how can I make the output of several commands all start from the same spot on the screen?
ANSI control characters.
Uh, I meant to say ANSI escape sequences (ANSI X3.64-1979). With those you can set the colours, the cursor position etc. They're plain text, the same that are used in PS1 to turn the shell prompt red when you're root. They're also used in the init scripts for writing "done" in green etc etc. To write in red text: echo -e "\E[1;32mDavid Rankin\E[0m" To set the cursor position: ESC[24;80H /Per -- Per Jessen, Zürich (5.3°C) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Mar 29, 2009, at 10:21 AM, David C. Rankin wrote:
Listmates,
In BASH, how can I make the output of several commands all start from the same spot on the screen? In c we used to have all these nice libraries that gave control over X,Y screen output. (IIRC we were actually manipulating the video buffer) But in bash, there doesn't seem to be any way to do this.
For example, if I have a simple counter and I want to see the numbers increasing without scrolling a line for every number output, I ended up having to do this (just paste it into the command line):
echo -en "\n\tThe count stands at: "; for ((i=1;i<=120;i++)); do mstrlen=${#i}; echo -en "$i"; sleep .1; for ((j=0;j<$mstrlen;j++)); do echo -en "\b"; done; done; echo -e "\n"
Surely there is an easier way. What say the bash gurus??
You need tput. Works on just about any terminal, including the one emulated in konsole/xterm/whatever. Roger Oberholtzer OPQ Systems / Ramböll RST Ramböll Sverige AB Kapellgränd 7 P.O. Box 4205 SE-102 65 Stockholm, Sweden Office: Int +46 8-615 60 20 Mobile: Int +46 70-815 1696 And remember: It is RSofT and there is always something under construction. It is like talking about large city with all constructions finished. Not impossible, but very unlikely. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Roger Oberholtzer wrote:
On Mar 29, 2009, at 10:21 AM, David C. Rankin wrote:
Listmates,
In BASH, how can I make the output of several commands all start from the same spot on the screen? In c we used to have all these nice libraries that gave control over X,Y screen output. (IIRC we were actually manipulating the video buffer) But in bash, there doesn't seem to be any way to do this.
For example, if I have a simple counter and I want to see the numbers increasing without scrolling a line for every number output, I ended up having to do this (just paste it into the command line):
echo -en "\n\tThe count stands at: "; for ((i=1;i<=120;i++)); do mstrlen=${#i}; echo -en "$i"; sleep .1; for ((j=0;j<$mstrlen;j++)); do echo -en "\b"; done; done; echo -e "\n"
Surely there is an easier way. What say the bash gurus??
You need tput. Works on just about any terminal, including the one emulated in konsole/xterm/whatever.
Roger Oberholtzer
Per, Roger, That's exactly what I needed. Somebody to point me to the escape sequences, (and I bet after tearing tput apart -- back to the escape sequences), so my quick scripts can take on a whole new level of form. Thanks. I'm sure you'll see some of the stray fragments of my use(ful|less) scripts shortly. Throw this on the command line ;-) let myx=1 myy=1 myup=1 myright=1; mystr="David Rankin ($myx,$myy,$myup,$myright)"; while :; do echo -en "\033[${myx};${myy}H\033[1;31m${mystr}\033[0m"; [[ $myx -eq $(($COLUMNS-${#mystr})) ]] && myright=0; [[ $myx -eq 1 ]] && myright=1; if [[ $myright -eq 1 ]]; then ((myx+=1)); else ((myx-=1)); fi; [[ $myy -eq $LINES ]] && myup=0; [[ $myy -eq 1 ]] && myup=1; if [[ $myup -eq 1 ]]; then ((myy+=1)); else ((myy-=1)); fi; mystr="David Rankin ($myx,$myy,$myup,$myright)"; sleep .5; done It crawls across the bottom for a second before bouncing, but I'll get to that later;-) -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello, On Sun, 29 Mar 2009, David C. Rankin wrote:
echo -en "\n\tThe count stands at: "; for ((i=1;i<=120;i++)); do mstrlen=${#i}; echo -en "$i"; sleep .1; for ((j=0;j<$mstrlen;j++)); do echo -en "\b"; done; done; echo -e "\n"
Surely there is an easier way. What say the bash gurus??
man console_codes Example: for i in $(seq 1 120); do printf "\e[2K\e[1GThe count stands at: % 3i" "$i" sleep .1 done echo HTH, -dnh -- Ceci n'est pas une .signature. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sun, 29 Mar 2009, David Haller wrote:-
Example: for i in $(seq 1 120); do
For counting up or down by one, there's no need to use seq. Bash can use ranges using {$start..$end} where $start and $end can be positive or negative numbers, or letters[0]. The above can be replaced by: for i in {1..120}; do [0] Using letters, keep and eye on the case. While {A..Z} and {a..z} will list the letters from A-Z and a-z, {A..z} list both upper and lower case letters as well as the characters [ ] ^ _ ` Regards, David Bolt -- Team Acorn: http://www.distributed.net/ OGR-NG @ ~100Mnodes RC5-72 @ ~1Mkeys/s openSUSE 10.3 32b | openSUSE 11.0 32b | | openSUSE 10.3 64b | openSUSE 11.0 64b | openSUSE 11.1 64b | openSUSE 10.3 PPC | RISC OS 3.6 | RISC OS 3.11 | TOS 4.02 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello, On Mon, 30 Mar 2009, David Bolt wrote:
On Sun, 29 Mar 2009, David Haller wrote:-
Example: for i in $(seq 1 120); do
For counting up or down by one, there's no need to use seq. Bash can use ranges using {$start..$end} where $start and $end can be positive or negative numbers, or letters[0]. The above can be replaced by:
for i in {1..120}; do
No it (mine) can't. $ bash -c 'for i in {1..120}; do echo "$i"; done; echo $BASH_VERSION' {1..120} 2.03.0(1)-release $ ksh -c 'for i in {1..120}; do echo "$i"; done; echo $KSH_VERSION' {1..120} @(#)PD KSH v5.2.14 99/07/13.2 $ ash -c 'for i in {1..120}; do echo "$i"; done;' {1..120} $ zsh -c 'for i in {1..120}; do echo "$i"; done; echo $ZSH_VERSION' 1 [..] 120 3.0.5 $ Don't assume everyone has the same shell as you have. And the question was not shell-, but terminal-specific. One more reason to show a portable solution. HTH, -dnh --
Murphy and Darwin are best mates, and both date the Fuckup Fairy. Yeah, that pretty much sums up my life these days. -- > P. Corlett and D. P. Murphy -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Mon, 30 Mar 2009, David Haller wrote:-
Hello,
Hello
No it (mine) can't.
$ bash -c 'for i in {1..120}; do echo "$i"; done; echo $BASH_VERSION' {1..120} 2.03.0(1)-release
You must be using an old and a rather unsupported version of SuSE to still be using bash 2.03. If I was to guess which version, I think it's probably one of the 6.x releases, as the supplied version when SuSE 7.0 was released was bash 2.04. Somewhere between 7.0 and 8.1, the supplied version was updated to v2.05. Bash 3.0, which supports ranges, was supplied with SuSE 9.2, and so anyone using a version released within the last 4 years would be able to use it rather than relying on having to use seq.
$ ksh -c 'for i in {1..120}; do echo "$i"; done; echo $KSH_VERSION' {1..120} @(#)PD KSH v5.2.14 99/07/13.2 $ ash -c 'for i in {1..120}; do echo "$i"; done;' {1..120} $ zsh -c 'for i in {1..120}; do echo "$i"; done; echo $ZSH_VERSION' 1 [..] 120 3.0.5 $
I'm not surprised it didn't work with those shells as the {..} construct is a (v3.0+) bash-ism.
Don't assume everyone has the same shell as you have.
I didn't. I tested using an old 9.3 installation, which has been out of support for almost 2 years and still waiting for me to update, and it worked there.
And the question was not shell-, but terminal-specific.
In this instance it was shell specific. The OP mentioned he wanted to know how to position test at specific points using a specific shell, namely bash. Regards, David Bolt -- Team Acorn: http://www.distributed.net/ OGR-NG @ ~100Mnodes RC5-72 @ ~1Mkeys/s openSUSE 10.3 32b | openSUSE 11.0 32b | | openSUSE 10.3 64b | openSUSE 11.0 64b | openSUSE 11.1 64b | openSUSE 10.3 PPC | RISC OS 3.6 | RISC OS 3.11 | TOS 4.02 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Mon, 2009-03-30 at 12:59 +0100, David Bolt wrote:
And the question was not shell-, but terminal-specific.
In this instance it was shell specific. The OP mentioned he wanted to know how to position test at specific points using a specific shell, namely bash.
look at tput -- Roger Oberholtzer OPQ Systems / Ramböll RST Ramböll Sverige AB Krukmakargatan 21 P.O. Box 17009 SE-104 62 Stockholm, Sweden Office: Int +46 8-615 60 20 Mobile: Int +46 70-815 1696 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (5)
-
David Bolt
-
David C. Rankin
-
David Haller
-
Per Jessen
-
Roger Oberholtzer