私は長いスクリプトの進捗状況を見て、出力しようとしています。 (後で進捗バーを計算するために進捗状況を使用したい)。while + pipeでbashのグローバル変数を使用していますか?
1 <-# before the first while)
2
3
4
5
6
7
8 <-# end of first while)
9
10
11 <-# end of second while)
のような出力になり、私は今、期待する何
#!/bin/bash
PROGRESS=0
updateprogress() {
PROGRESS=$((PROGRESS + 1))
echo $PROGRESS
}
<do something>
updateprogress
sudo cat /root/.virtualMachines | while read -r name ipAddr # <-7 lines
do
<do something>
updateprogress
done
sudo cat /root/.virtualServices | while read -r name ipAddr # <-3 lines
do
<do something>
updateprogress
done
しかし、私が得ることので問題はあり
1 <-# before first while)
2
3
4
5
6
7
8 <-# end of first while
2
3
4 <-# end of second while
次のとおりです。ここで
が短縮例です。グローバル/ローカルスコープに関するものですが、どのようにグローバル変数$ PROGRESSのみを使うことができますか?すべての関数呼び出しについて?
パイプが関与していますか?例えば。 'コマンド| while ... ' – choroba
はい、確かに私の質問に更新します – derHugo
あなたの質問に感謝;)私はあなたの入力と私は答え[ここ](https://stackoverflow.com/questions/16854280/ a-variable-modified-inside-while-while-loop-not-not-remembered) – derHugo