I'm having difficulties understanding the following example I created.
The variable glob_var gets changed inside the test() function, but the original value remains outside of the function:
test() {
read var
glob_var=$var
echo '$glob_var in test(): '$glob_var
}
glob_var='org'
echo '$glob_var start: '$glob_var
echo new | test
echo '$glob_var end: '$glob_var
Output
$glob_var start: org
$glob_var in test(): new
$glob_var end: org
I'm suspecting that the pipe starts a new process. If that's the case, what would be an alternative way to retrieve values from the test function?