#!/bin/bash
echo -e "10\n20\n100\n200" > file.txt
number=0
cat file.txt | \
while read line
do
if test $line -gt 100
then
number=$line
echo "Inside while loop number=$number"
break
fi
done
echo "Outside while loop number=$number"
The output of this script is
Inside while loop number=200
Outside while loop number=0
Why the variable $number is losing its value outside while loop
even though it's a global value?
Thanks,
Mahendra