#!/bin/bash
#隱藏游標
c_hide_cursor='\033[?25l'
#顯示游標
c_show_cursor='\033[?25h'
#函式體
timeout(){
#隱藏游標
echo -en "$c_hide_cursor"
#這是一個無限回圈,如果要定時結束,可以在回圈內添加條件.
while true ;do
printf "\b" #洗掉一個字符
printf "/" #添加一個字符 "/"
sleep 0.1 #等待0.1秒
printf "\b|" #洗掉一個字符,再添加一個字符 "|"
sleep 0.1
printf "\b\\" # "\" 反斜杠需要兩個反斜杠才能顯示
sleep 0.1
printf "\b-"
sleep 0.1
printf "\b|"
done
}
#列印資訊,不換行
printf "請稍后: "
#呼叫函式
timeout
#函式結束后再顯示游標. 由于我設定無限回圈所以需要設定條件, 讓函式自動結束再執行以下陳述句
echo -en "$c_show_cursor"
插圖

計數器
timeout(){ #這個腳本最多計算到9的數字內,
a=1
while [ 9 != $a ];do
a=$(($a+1))
echo -en "$a"
sleep 1
echo -en "\b"
done
}
printf "請稍等:"
timeout
截圖

計數器 2
timeout(){ #這個腳本需要換行計數,不然會洗掉計數的字符,
a=1
while [ 99 != $a ];do
a=$(($a+1))
printf "$a"
sleep 0.1
printf "\b\b\b"
done
}
printf "請稍等: \n"
timeout
截圖

計數條
timeout(){
a=1
while [ 50 != $a ];do
a=$(($a+1))
printf "#"
sleep 0.1
done
}
printf "請稍等: "
timeout
printf "\n[ok]"
截圖

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/458600.html
標籤:其他
