백그라운드에 while 루프를 넣고 count 값을 증가시키려고 하는데 백그라운드 while 루프가 count 변수를 업데이트하지 않습니다.
#!/bin/bash
count=0
((count++))
echo " External $count"
while [ $count -ne 0 ]
do
echo "Inside $count.. sleeping 5"
sleep 5
done &
sleep 10
((count++))
echo " External $count"
sleep 20
((count--))
((count--))
wait
산출:
External 1
Inside 1.. sleeping 5
Inside 1.. sleeping 5
External 2
Inside 1.. sleeping 5
Inside 1.. sleeping 5
Inside 1.. sleeping 5
예상 출력:
External 1
Inside 1.. sleeping 5
Inside 1.. sleeping 5
External 2
Inside 2.. sleeping 5
Inside 2.. sleeping 5
Inside 2.. sleeping 5