Home:ALL Converter>Get variable outside while loop shell script

Get variable outside while loop shell script

Ask Time:2020-05-21T06:30:52         Author:Carlos H.

Json Formatter

I would like the get the content of variable outside the while loop using shell script

For example:

::

count = 5
while [ @count -gt 0]; do
a=3
b=4
if ( a > b)
 result = "UP"
else
 result = "DOWN"
fi
count=$[ $count - 1]
done

echo $result

$result appears empty every time!

I just want the content of result outside the loop.

Can anyone help on this issue! I know that the variable inseide the loop is executed in sub-shell, but I tried several tips and doesn't works!

Thanks in avdance

Author:Carlos H.,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/61924020/get-variable-outside-while-loop-shell-script
yy