关于进度条的显示
发表于:2007-05-26来源:作者:点击数:
标签:
[code:1:1b5d7444d4]1、使用一系列圆点来指示进度 --------后台循环------------ #!/bin/bash whiletrue do echo-e.\c sleep3 donenbsp;-9$BG_PID -----------后台函数--------- #!/bin/bash dots whiletrue do ech
[code:1:1b5d7444d4]1、使用一系列圆点来指示进度
--------后台循环------------
#!/bin/bash
while true
do
echo -e ".\c"
sleep 3
done &
BG_PID=$!
./test.sh
kill -9 $BG_PID
-----------后台函数---------
#!/bin/bash
dots()
{
while true
do
echo -e ".\c"
sleep 3
done
}
#########################################
########## Begin of Main ################
#########################################
dots &
BG_PID=$!
./test.sh
kill -9 $BG_PID
2、使用一条旋转线来指示进度
#!/bin/bash
rotate()
{
INTERVAL = 1 # Sleep time between "twirls"
TCOUNT = "0" # For each TCOUNT the line twirls one increment
while : # Loop forever ...until this function is killed
do
TCOUNT = $(($TCOUNT + 1)) # Increment the TCOUNT
case $TCOUNT in
"1") echo -e '-' "\b\c"
sleep $INTERVAL
;;
"2") echo -e '\\' "\b\c"
sleep $INTERVAL
;;
"3") echo -e "|\b\c"
sleep $INTERVAL
;;
"4") echo -e "/\b\c"
sleep $INTERVAL
;;
* ) TCOUNT="0" ;; # Reset the TCOUNT to "0",zero
esac
done
} # End of Function rotate
#########################################
########## Begin of Main ################
#########################################
rotate &
ROTATE_PID=$!
./test.sh
kill -9 $ROTATE_PID
# cleanup...
echo -e "\b\b "
# End of Example
[/code:1:1b5d7444d4]
yuri-master 回复于:2005-07-10 20:46:03
|
小弟不才,来凑个数
[code:1:f870dbef35]
#!/bin/sh
# Yuri.G
# Yuri.unix@gmail.com
# Yuri Family Data Center
# 2005-07-10
tr()
{
sl='sleep 0.5'
while true
do
echo -e '-'"\b\c";$sl
echo -e '\\'"\b\c";$sl
echo -e "|\b\c";$sl
echo -e "/\b\c";$sl
done
}
tr &
TR_PID=$!#让进度条显示操作后台运行,并获取它的进程ID
sleep 10#把这个换成你要做的事情。
kill -9 $TR_PID#kill掉进度条
[/code:1:f870dbef35]
|
joyaid 回复于:2005-07-11 15:05:28
|
楼上这样写不行"tr &;TR_PID=$!#"
&;不能在一起.
|
yuri-master 回复于:2005-07-11 16:43:38
|
明白了.马上改
|
yuri-master 回复于:2005-07-12 15:01:12
|
[root@Fedora4 demo]# sh ww.sh
..........ww.sh: line 13: 29632 已杀死 while true; do
echo -e ".\c"; sleep 0.6;
done
[root@Fedora4 demo]#
他会提示已杀死怎么去掉啊?
|
原文转自:http://www.ltesting.net