The following shell scrip will check the disk space and change the variable diskfull
to 1
if the usage is more than 10%
The last echo always shows
This is a side-effect of using while
in a pipeline. There are two workarounds:
1) put the while
loop and all the variables it uses in a separate scope as demonstrated by levislevis86
some | complicated | pipeline | {
while read line; do
foo=$( some calculation )
done
do_something_with $foo
}
# $foo not available here
2) if your shell allows it, use process substitution and you can redirect the output of your pipeline to the input of the while loop
while read line; do
foo=$( some calculation )}
done < <(some | complicated | pipeline)
do_something_with $foo