Quote:
Originally Posted by druuna
Hi,
No it doesn't ....
Using the script you posted (post #2) altered to show the content of the mountedon variable inside and outside the loop:
|
You are right, my script is wrong. However, the problem is not caused by any encapsulation while would offer, but by the fact that, as part of a pipeline, while is run in a subshell.
To avoid writing to disk, I would suggest this form:
Code:
#!/bin/bash
while read outstring;
do
percentuse=$(echo $outstring | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $outstring | awk '{ print $2 }' )
mountedon1=$(echo $outstring | awk '{ print $3 }' )
if [[ $percentuse -ge 50 ]]; then
mountedon=$mountedon\ $mountedon1
fi
echo "[IN LOOP] mountedon : $mountedon"
done < <(df -Ph | awk '{ print $5 " " $1 " " $6 }')
echo "[OUSIDE LOOP] mountedon : $mountedon"
Thank you for drawing my attention to this bug.
Now I see that you posted the same solution. How can you post a solution if you don't explain the cause of the bug correctly?