The following code works differently depending on which way Parse_Short_Switches() is called. After calling the function 'Parse_Short_Switches' by using result=$(Parse_Short_Switches), the value of $error_flag is NOT set to -1 as I would expect.
After calling the function 'Parse_Short_Switches' by simply using Parse_Short_Switches, the the value of $error_flag is set to -1 as I would expect.
Any help would be greatly appreciated. Thanks
#!/bin/bash
function Parse_Short_Switches()
{
echo "error_flag inside of the function= $error_flag" 1>&2
error_flag="-1"
echo "blah blah ..."
}
# --- MAIN ---
error_flag="999"
echo "error_flag= $error_flag"
#result=$(Parse_Short_Switches)
Parse_Short_Switches
echo "error_flag= $error_flag"