I have this code in a bash script:
r2g(){
echo "executable is: $0" # "/bin/bash"
(
set -e;
r2g_internal "$@" \
2> >( while read line; do echo "r2g error: $line"; done ) \
1> >( while read line; do echo "r2g: $line"; done )
)
exit_code="$?"
if [[ "$exit_code" != "0" ]]; then
echo "something experienced an error, to see log, run: r2g_view_log";
return 1;
fi
}
what's happening is that after r2g_internal runs, sh is launched by some process and it apparently tries to resource the bash env, and I get his weird syntax error from sh:
r2g error: sh: r2g: line 2: syntax error near unexpected token `>'
r2g error: sh: r2g: line 2: ` r2g_internal "$@" 2> >( while read line; do echo "r2g error: $line"; done ) > >( while read line; do echo "r2g: $line"; done ) );'
r2g error: sh: error importing function definition for `r2g'
I made a video demoing the problem: https://www.useloom.com/share/82f23ebfe6754412a20be057957e45f4
and a follow up vid: https://www.useloom.com/share/0465c2857cc244879b52b7bdb516243e
when npm install runs, some sh process must be launched by npm..git also seems to launch an sh process sometimes when I run git commands, and the same type of syntax errors show up in the terminal in that case.
I cannot figure out why a sh process launched via bash would then try to source some of the bash code from the parent shell/env?
The video makes the problem clearer (I hope).
if I call unset -f r2g, the problem goes away immediately. So I guess /bin/sh is calling my r2g function, but I don't know how or why.
Here is the source for r2g and r2g_internal together: https://gist.github.com/ORESoftware/0fa7e3d6b75a65b17b6b126a7bec3397