I'm getting some strange behavior from bash witch I cannot understand. I've tryed to google this problem some times but with no luck.
I just copy/paste a small shell script .. (It a outcome of a bigger one - but gives a picture of the problem).
Code: Select all
[# ========= check_if_burn() - Checks whatever if a iso allready is burned out =
check_if_burn() {
was_ok=0
ls | while read f
do
ext=${f##*_}
if [ "$ext" = "SUCCESS" ]
then
echo "There was a success file: $f"
was_ok=1 ### Why wont this change?
fi
done
return $was_ok
} # check_if_burn end
check_if_burn
echo "Exitcode was:$?"
The strange part is the following.
I will get a echo output while having a success file - but the variable was_ok never changes (or gets set to 0?)
When i set the variable in the top of the function - it will change, and if I do it in the buttom of the script it will change. Its -only- while its into some sort of loop its giving me trouble (I even tried with "for" and "until").
So - trouble is - why can I set a variable in a loop?
looking forward to some great reply s - this has been nagging me
/~HJess