根据调用 Parse_Short_Switches() 的方式,以下代码的工作方式有所不同。使用 result=$(Parse_Short_Switches) 调用函数“Parse_Short_Switches”后,$error_flag 的值并未像我预期的那样设置为 -1。
通过简单地使用 Parse_Short_Switches 调用函数“Parse_Short_Switches”后,$error_flag 的值按照我的预期设置为 -1。
任何帮助将不胜感激。谢谢
#!/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"
Run Code Online (Sandbox Code Playgroud)