0
次のコードは、進捗バーをHTMLページに表示しています。それは正常に動作しますが、多くのコード行にまで及んでいます。IF文をFORまたはWHILEに変換する(シェルスクリプト)
QUESTION:
- どのように私はその機能を複製、for
またはwhile
ループにこれを変換するに行きますか?
if [ $per_usage -ge 1 ] && [ $per_usage -le 10 ]
then
indg="|"
indb=""
indr=""
elif [ $per_usage -gt 10 ] && [ $per_usage -le 20 ]
then
indg="||"
indb=""
indr=""
elif [ $per_usage -gt 20 ] && [ $per_usage -le 30 ]
then
indg="|||"
indb=""
indr=""
elif [ $per_usage -gt 30 ] && [ $per_usage -le 40 ]
then
indg="||||"
indb=""
indr=""
elif [ $per_usage -gt 40 ] && [ $per_usage -le 50 ]
then
indg="|||||"
indb=""
indr=""
elif [ $per_usage -gt 50 ] && [ $per_usage -le 60 ]
then
indg="|||||"
indb="|"
indr=""
elif [ $per_usage -gt 60 ] && [ $per_usage -le 70 ]
then
indg="|||||"
indb="||"
indr=""
elif [ $per_usage -gt 70 ] && [ $per_usage -le 80 ]
then
indg="|||||"
indb="|||"
indr=""
elif [ $per_usage -gt 80 ] && [ $per_usage -le 90 ]
then
indg="|||||"
indb="||"
indr="||"
elif [ $per_usage -gt 90 ]
then
indg=""
indb=""
indr="||||||||||"
else
indg=""
indb=""
indr=""
fi
per_usage値は41
41 % |||||
ある場合たとえば、私の出力は以下のようであるが、事前にありがとうございます。
返信する時間を取ってくれてありがとうジョン。魅力のように動作します。私はこれを私のプログラムで以下のコードだけで適合させることができました。もし "[$ per_usage" -le100] && ["$ per_usage" -ge 0];なら、get_string(){ per_usage = "$ 1" ; echo -en "$ {per_usage}%\ t" printf "%0.s |" $(seq 1 $ bars) エコー fi } –
大歓迎です!うれしいことはあなたのために働いた。 –