I can’t understand why userType is not changing.
I know for certain it’s successfully reaching determineType, but it isn’t changing the value to “bbb” when I try to print out userType later.
userType="aaa"
function determineType {
userType="bbb"
}
function checkUser {
cat users.csv | \
while read userLine; do
if [[ $userLine =~ .*$user.* ]]
then
determineType
echo "1"
fi
done
echo "0"
}
As soulseekah said in a comment, your
whileloop is executed in a subshell. Instead, do (and, as a benefit, you get rid of the useless use of cat):Note. I also changed a few things:
returninstead ofechofor returning values: you’d run into the same problem again with anecho: you’d probably use your function checkUser in another subshell to obtain the value returned by theecho.