I'm a long time unix (not linux) programmer, mainly shell scripts.
Unix does not know about bash, but rather ksh or sh.
So I often build stuff like this:
Code:
n=0
du | sort -n | while read size dir
do
if [ "$size" -gt 100000 ]
then
n=$((n+1))
fi
done
echo "Found $n too big files"
the question is
not how to reformulate this differently using awk or perl.
The question is:
in ksh this script returns the correct value
in bash it always returns 0
This is because in ksh the last command in the pipe runs in the current process, whereas in bash the first command runs in the current proces. Result: the modified variables are lost.
I'm still puzzled that his is the case and that nobody really cares about.
Maybe I'm missing the point and there is some simple environment variable or other setting to change to enable ksh compatible behaviour.
Georges