Imported from ../bash-2.0.tar.gz.
[platform/upstream/bash.git] / examples / scripts / scrollbar
1 #!/bin/bash
2 #
3 # scrollbar - display scrolling text
4 #
5 # usage: scrollbar args
6 #
7 # A cute hack originally from Heiner Steven <hs@bintec.de>
8 #
9 # converted from ksh syntax to bash v2 syntax by Chet Ramey
10
11 WIDTH=${COLUMNS:-80}
12
13 [ $# -lt 1 ] && set -- TESTING
14
15 # Posix.2 compatible printf command or bash loadable builtin
16 # in examples/loadables/printf
17 Text=$(printf "%-${WIDTH}s" "$*")
18 Text=$(echo "$Text" | tr ' ' '_')
19
20 while :
21 do
22         printf "%-.${WIDTH}s\r" "$Text"
23         LastC=$(expr "$Text" : '.*\(.\)$')
24         Text=$(printf "%-.${WIDTH}s" "$LastC$Text")
25 done