sh is evaluating bash code from parent shell, and breaking down

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite
2












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







share|improve this question





















  • It looks to me as though sh is reading the script file that you intend for bash.
    – Jeff Schaller
    May 9 at 0:45










  • nah in the video I demonstrate that to not be the case (as far as I can tell)
    – Alexander Mills
    May 9 at 0:47










  • sh is definitely evaluating the script, but why sh is evaluating the script is not clear
    – Alexander Mills
    May 9 at 0:48










  • You should post what r2g_internal code
    – cuonglm
    May 9 at 1:26










  • Sure thing, here is the code: gist.github.com/ORESoftware/0fa7e3d6b75a65b17b6b126a7bec3397
    – Alexander Mills
    May 9 at 1:29














up vote
3
down vote

favorite
2












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







share|improve this question





















  • It looks to me as though sh is reading the script file that you intend for bash.
    – Jeff Schaller
    May 9 at 0:45










  • nah in the video I demonstrate that to not be the case (as far as I can tell)
    – Alexander Mills
    May 9 at 0:47










  • sh is definitely evaluating the script, but why sh is evaluating the script is not clear
    – Alexander Mills
    May 9 at 0:48










  • You should post what r2g_internal code
    – cuonglm
    May 9 at 1:26










  • Sure thing, here is the code: gist.github.com/ORESoftware/0fa7e3d6b75a65b17b6b126a7bec3397
    – Alexander Mills
    May 9 at 1:29












up vote
3
down vote

favorite
2









up vote
3
down vote

favorite
2






2





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







share|improve this question













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









share|improve this question












share|improve this question




share|improve this question








edited May 10 at 7:47
























asked May 9 at 0:36









Alexander Mills

1,885929




1,885929











  • It looks to me as though sh is reading the script file that you intend for bash.
    – Jeff Schaller
    May 9 at 0:45










  • nah in the video I demonstrate that to not be the case (as far as I can tell)
    – Alexander Mills
    May 9 at 0:47










  • sh is definitely evaluating the script, but why sh is evaluating the script is not clear
    – Alexander Mills
    May 9 at 0:48










  • You should post what r2g_internal code
    – cuonglm
    May 9 at 1:26










  • Sure thing, here is the code: gist.github.com/ORESoftware/0fa7e3d6b75a65b17b6b126a7bec3397
    – Alexander Mills
    May 9 at 1:29
















  • It looks to me as though sh is reading the script file that you intend for bash.
    – Jeff Schaller
    May 9 at 0:45










  • nah in the video I demonstrate that to not be the case (as far as I can tell)
    – Alexander Mills
    May 9 at 0:47










  • sh is definitely evaluating the script, but why sh is evaluating the script is not clear
    – Alexander Mills
    May 9 at 0:48










  • You should post what r2g_internal code
    – cuonglm
    May 9 at 1:26










  • Sure thing, here is the code: gist.github.com/ORESoftware/0fa7e3d6b75a65b17b6b126a7bec3397
    – Alexander Mills
    May 9 at 1:29















It looks to me as though sh is reading the script file that you intend for bash.
– Jeff Schaller
May 9 at 0:45




It looks to me as though sh is reading the script file that you intend for bash.
– Jeff Schaller
May 9 at 0:45












nah in the video I demonstrate that to not be the case (as far as I can tell)
– Alexander Mills
May 9 at 0:47




nah in the video I demonstrate that to not be the case (as far as I can tell)
– Alexander Mills
May 9 at 0:47












sh is definitely evaluating the script, but why sh is evaluating the script is not clear
– Alexander Mills
May 9 at 0:48




sh is definitely evaluating the script, but why sh is evaluating the script is not clear
– Alexander Mills
May 9 at 0:48












You should post what r2g_internal code
– cuonglm
May 9 at 1:26




You should post what r2g_internal code
– cuonglm
May 9 at 1:26












Sure thing, here is the code: gist.github.com/ORESoftware/0fa7e3d6b75a65b17b6b126a7bec3397
– Alexander Mills
May 9 at 1:29




Sure thing, here is the code: gist.github.com/ORESoftware/0fa7e3d6b75a65b17b6b126a7bec3397
– Alexander Mills
May 9 at 1:29










2 Answers
2






active

oldest

votes

















up vote
3
down vote













This won't probably solve your problem, just take a moment for a few notes, too long for a comment:




  • If you don't need to do so, don't structure your code as a single line, I am quoting:




    r2g_internal "$@" 2> >( while read line; do echo "r2g error: $line"; done ) 1> >( while read line; do echo "r2g: $line"; done )



    It is unreadable for others and even to you I suspect.




  • I'll start from the beginning:



    I don't see a shebang like:



    #!/bin/bash


    or



    #!/bin/sh


    and so on.



  • If you don't need Bash, but this shell script seems to need it, use POSIX sh for portability purposes.


  • Since exit_code is used only once, you can avoid it.


  • You don't need to quote what number always is. In this instance "$?".



  • Avoid Bash-specific [[ .. ]], and use classic test command instead. In this instance:



    if [ $? -ne 0 ]



  • You don't need a semi-colon at the end of the line, you may use structure like this one:



    if [ $? -ne 0 ]
    then
    echo "something experienced an error, to see log, run: r2g_view_log"
    return 1
    fi


  • Use -r switch with read. Read more about this topic here.


  • I made a few other adjustments, check it out, please.


  • I'm unsure, if that is intentional, but I will suppose not; where you used return 1, from what I can see, should be exit 1.



  • The shebang can contain the set -e as follows:



    #!/bin/bash -e



Rewritten based on above:



#!/bin/bash -e

r2g()


echo "executable name is: $0"

r2g_internal "$@" 2> >( while read -r line; do echo "r2g error: $line"; done ) >( while read -r line; do echo "r2g: $line"; done )

if [ $? -ne 0 ]
then
echo "something experienced an error, to see log, run: r2g_view_log"
exit 1
fi







share|improve this answer























  • if i use set -e globally and it gets set in my shell, any command that exits with non zero will close the terminal window. this script is getting sourced by all bash shells so..
    – Alexander Mills
    May 10 at 16:47










  • the shebang/hashbang also doesnt matter. that wont determine which process calls the function.
    – Alexander Mills
    May 10 at 16:48

















up vote
-1
down vote













No offence but have you tried to read and understand error message:




syntax error near unexpected token `>'




It explicitly tells that your code contains obvious error: 2> >(.
'>' is to direct standard output into file. Your are trying to direct output of r2g_internal to script reading from standard input. You must use '|' not '>'.



And one more error -- you can direct stdout and stderr to separate files but you can not easily direct them to separate scripts. You will have to write them first into files and then process them separately.



r2g_internal "$@" 1> stdout.txt 2> stderr.txt
cat stderr.txt | ( while read line; do echo "r2g error: $line"; done )
cat stdout.txt | ( while read line; do echo "r2g: $line"; done )





share|improve this answer

















  • 1




    Note that using process substitution (>(...)) is exactly what he wants to be doing to filter the output from r2g_internal as it arrives.
    – Kusalananda
    May 9 at 15:24











  • Although process substitution is available only in ksh bash zsh -- and bash not when POSIX mode, which may be the cause of the error message. Cf unix.stackexchange.com/questions/309547/…
    – dave_thompson_085
    May 10 at 6:47











  • well it says it's sh that is barfing on the syntax
    – Alexander Mills
    May 19 at 7:58










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442660%2fsh-is-evaluating-bash-code-from-parent-shell-and-breaking-down%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote













This won't probably solve your problem, just take a moment for a few notes, too long for a comment:




  • If you don't need to do so, don't structure your code as a single line, I am quoting:




    r2g_internal "$@" 2> >( while read line; do echo "r2g error: $line"; done ) 1> >( while read line; do echo "r2g: $line"; done )



    It is unreadable for others and even to you I suspect.




  • I'll start from the beginning:



    I don't see a shebang like:



    #!/bin/bash


    or



    #!/bin/sh


    and so on.



  • If you don't need Bash, but this shell script seems to need it, use POSIX sh for portability purposes.


  • Since exit_code is used only once, you can avoid it.


  • You don't need to quote what number always is. In this instance "$?".



  • Avoid Bash-specific [[ .. ]], and use classic test command instead. In this instance:



    if [ $? -ne 0 ]



  • You don't need a semi-colon at the end of the line, you may use structure like this one:



    if [ $? -ne 0 ]
    then
    echo "something experienced an error, to see log, run: r2g_view_log"
    return 1
    fi


  • Use -r switch with read. Read more about this topic here.


  • I made a few other adjustments, check it out, please.


  • I'm unsure, if that is intentional, but I will suppose not; where you used return 1, from what I can see, should be exit 1.



  • The shebang can contain the set -e as follows:



    #!/bin/bash -e



Rewritten based on above:



#!/bin/bash -e

r2g()


echo "executable name is: $0"

r2g_internal "$@" 2> >( while read -r line; do echo "r2g error: $line"; done ) >( while read -r line; do echo "r2g: $line"; done )

if [ $? -ne 0 ]
then
echo "something experienced an error, to see log, run: r2g_view_log"
exit 1
fi







share|improve this answer























  • if i use set -e globally and it gets set in my shell, any command that exits with non zero will close the terminal window. this script is getting sourced by all bash shells so..
    – Alexander Mills
    May 10 at 16:47










  • the shebang/hashbang also doesnt matter. that wont determine which process calls the function.
    – Alexander Mills
    May 10 at 16:48














up vote
3
down vote













This won't probably solve your problem, just take a moment for a few notes, too long for a comment:




  • If you don't need to do so, don't structure your code as a single line, I am quoting:




    r2g_internal "$@" 2> >( while read line; do echo "r2g error: $line"; done ) 1> >( while read line; do echo "r2g: $line"; done )



    It is unreadable for others and even to you I suspect.




  • I'll start from the beginning:



    I don't see a shebang like:



    #!/bin/bash


    or



    #!/bin/sh


    and so on.



  • If you don't need Bash, but this shell script seems to need it, use POSIX sh for portability purposes.


  • Since exit_code is used only once, you can avoid it.


  • You don't need to quote what number always is. In this instance "$?".



  • Avoid Bash-specific [[ .. ]], and use classic test command instead. In this instance:



    if [ $? -ne 0 ]



  • You don't need a semi-colon at the end of the line, you may use structure like this one:



    if [ $? -ne 0 ]
    then
    echo "something experienced an error, to see log, run: r2g_view_log"
    return 1
    fi


  • Use -r switch with read. Read more about this topic here.


  • I made a few other adjustments, check it out, please.


  • I'm unsure, if that is intentional, but I will suppose not; where you used return 1, from what I can see, should be exit 1.



  • The shebang can contain the set -e as follows:



    #!/bin/bash -e



Rewritten based on above:



#!/bin/bash -e

r2g()


echo "executable name is: $0"

r2g_internal "$@" 2> >( while read -r line; do echo "r2g error: $line"; done ) >( while read -r line; do echo "r2g: $line"; done )

if [ $? -ne 0 ]
then
echo "something experienced an error, to see log, run: r2g_view_log"
exit 1
fi







share|improve this answer























  • if i use set -e globally and it gets set in my shell, any command that exits with non zero will close the terminal window. this script is getting sourced by all bash shells so..
    – Alexander Mills
    May 10 at 16:47










  • the shebang/hashbang also doesnt matter. that wont determine which process calls the function.
    – Alexander Mills
    May 10 at 16:48












up vote
3
down vote










up vote
3
down vote









This won't probably solve your problem, just take a moment for a few notes, too long for a comment:




  • If you don't need to do so, don't structure your code as a single line, I am quoting:




    r2g_internal "$@" 2> >( while read line; do echo "r2g error: $line"; done ) 1> >( while read line; do echo "r2g: $line"; done )



    It is unreadable for others and even to you I suspect.




  • I'll start from the beginning:



    I don't see a shebang like:



    #!/bin/bash


    or



    #!/bin/sh


    and so on.



  • If you don't need Bash, but this shell script seems to need it, use POSIX sh for portability purposes.


  • Since exit_code is used only once, you can avoid it.


  • You don't need to quote what number always is. In this instance "$?".



  • Avoid Bash-specific [[ .. ]], and use classic test command instead. In this instance:



    if [ $? -ne 0 ]



  • You don't need a semi-colon at the end of the line, you may use structure like this one:



    if [ $? -ne 0 ]
    then
    echo "something experienced an error, to see log, run: r2g_view_log"
    return 1
    fi


  • Use -r switch with read. Read more about this topic here.


  • I made a few other adjustments, check it out, please.


  • I'm unsure, if that is intentional, but I will suppose not; where you used return 1, from what I can see, should be exit 1.



  • The shebang can contain the set -e as follows:



    #!/bin/bash -e



Rewritten based on above:



#!/bin/bash -e

r2g()


echo "executable name is: $0"

r2g_internal "$@" 2> >( while read -r line; do echo "r2g error: $line"; done ) >( while read -r line; do echo "r2g: $line"; done )

if [ $? -ne 0 ]
then
echo "something experienced an error, to see log, run: r2g_view_log"
exit 1
fi







share|improve this answer















This won't probably solve your problem, just take a moment for a few notes, too long for a comment:




  • If you don't need to do so, don't structure your code as a single line, I am quoting:




    r2g_internal "$@" 2> >( while read line; do echo "r2g error: $line"; done ) 1> >( while read line; do echo "r2g: $line"; done )



    It is unreadable for others and even to you I suspect.




  • I'll start from the beginning:



    I don't see a shebang like:



    #!/bin/bash


    or



    #!/bin/sh


    and so on.



  • If you don't need Bash, but this shell script seems to need it, use POSIX sh for portability purposes.


  • Since exit_code is used only once, you can avoid it.


  • You don't need to quote what number always is. In this instance "$?".



  • Avoid Bash-specific [[ .. ]], and use classic test command instead. In this instance:



    if [ $? -ne 0 ]



  • You don't need a semi-colon at the end of the line, you may use structure like this one:



    if [ $? -ne 0 ]
    then
    echo "something experienced an error, to see log, run: r2g_view_log"
    return 1
    fi


  • Use -r switch with read. Read more about this topic here.


  • I made a few other adjustments, check it out, please.


  • I'm unsure, if that is intentional, but I will suppose not; where you used return 1, from what I can see, should be exit 1.



  • The shebang can contain the set -e as follows:



    #!/bin/bash -e



Rewritten based on above:



#!/bin/bash -e

r2g()


echo "executable name is: $0"

r2g_internal "$@" 2> >( while read -r line; do echo "r2g error: $line"; done ) >( while read -r line; do echo "r2g: $line"; done )

if [ $? -ne 0 ]
then
echo "something experienced an error, to see log, run: r2g_view_log"
exit 1
fi








share|improve this answer















share|improve this answer



share|improve this answer








edited May 9 at 15:22


























answered May 9 at 8:31









Vlastimil

6,3011146116




6,3011146116











  • if i use set -e globally and it gets set in my shell, any command that exits with non zero will close the terminal window. this script is getting sourced by all bash shells so..
    – Alexander Mills
    May 10 at 16:47










  • the shebang/hashbang also doesnt matter. that wont determine which process calls the function.
    – Alexander Mills
    May 10 at 16:48
















  • if i use set -e globally and it gets set in my shell, any command that exits with non zero will close the terminal window. this script is getting sourced by all bash shells so..
    – Alexander Mills
    May 10 at 16:47










  • the shebang/hashbang also doesnt matter. that wont determine which process calls the function.
    – Alexander Mills
    May 10 at 16:48















if i use set -e globally and it gets set in my shell, any command that exits with non zero will close the terminal window. this script is getting sourced by all bash shells so..
– Alexander Mills
May 10 at 16:47




if i use set -e globally and it gets set in my shell, any command that exits with non zero will close the terminal window. this script is getting sourced by all bash shells so..
– Alexander Mills
May 10 at 16:47












the shebang/hashbang also doesnt matter. that wont determine which process calls the function.
– Alexander Mills
May 10 at 16:48




the shebang/hashbang also doesnt matter. that wont determine which process calls the function.
– Alexander Mills
May 10 at 16:48












up vote
-1
down vote













No offence but have you tried to read and understand error message:




syntax error near unexpected token `>'




It explicitly tells that your code contains obvious error: 2> >(.
'>' is to direct standard output into file. Your are trying to direct output of r2g_internal to script reading from standard input. You must use '|' not '>'.



And one more error -- you can direct stdout and stderr to separate files but you can not easily direct them to separate scripts. You will have to write them first into files and then process them separately.



r2g_internal "$@" 1> stdout.txt 2> stderr.txt
cat stderr.txt | ( while read line; do echo "r2g error: $line"; done )
cat stdout.txt | ( while read line; do echo "r2g: $line"; done )





share|improve this answer

















  • 1




    Note that using process substitution (>(...)) is exactly what he wants to be doing to filter the output from r2g_internal as it arrives.
    – Kusalananda
    May 9 at 15:24











  • Although process substitution is available only in ksh bash zsh -- and bash not when POSIX mode, which may be the cause of the error message. Cf unix.stackexchange.com/questions/309547/…
    – dave_thompson_085
    May 10 at 6:47











  • well it says it's sh that is barfing on the syntax
    – Alexander Mills
    May 19 at 7:58














up vote
-1
down vote













No offence but have you tried to read and understand error message:




syntax error near unexpected token `>'




It explicitly tells that your code contains obvious error: 2> >(.
'>' is to direct standard output into file. Your are trying to direct output of r2g_internal to script reading from standard input. You must use '|' not '>'.



And one more error -- you can direct stdout and stderr to separate files but you can not easily direct them to separate scripts. You will have to write them first into files and then process them separately.



r2g_internal "$@" 1> stdout.txt 2> stderr.txt
cat stderr.txt | ( while read line; do echo "r2g error: $line"; done )
cat stdout.txt | ( while read line; do echo "r2g: $line"; done )





share|improve this answer

















  • 1




    Note that using process substitution (>(...)) is exactly what he wants to be doing to filter the output from r2g_internal as it arrives.
    – Kusalananda
    May 9 at 15:24











  • Although process substitution is available only in ksh bash zsh -- and bash not when POSIX mode, which may be the cause of the error message. Cf unix.stackexchange.com/questions/309547/…
    – dave_thompson_085
    May 10 at 6:47











  • well it says it's sh that is barfing on the syntax
    – Alexander Mills
    May 19 at 7:58












up vote
-1
down vote










up vote
-1
down vote









No offence but have you tried to read and understand error message:




syntax error near unexpected token `>'




It explicitly tells that your code contains obvious error: 2> >(.
'>' is to direct standard output into file. Your are trying to direct output of r2g_internal to script reading from standard input. You must use '|' not '>'.



And one more error -- you can direct stdout and stderr to separate files but you can not easily direct them to separate scripts. You will have to write them first into files and then process them separately.



r2g_internal "$@" 1> stdout.txt 2> stderr.txt
cat stderr.txt | ( while read line; do echo "r2g error: $line"; done )
cat stdout.txt | ( while read line; do echo "r2g: $line"; done )





share|improve this answer













No offence but have you tried to read and understand error message:




syntax error near unexpected token `>'




It explicitly tells that your code contains obvious error: 2> >(.
'>' is to direct standard output into file. Your are trying to direct output of r2g_internal to script reading from standard input. You must use '|' not '>'.



And one more error -- you can direct stdout and stderr to separate files but you can not easily direct them to separate scripts. You will have to write them first into files and then process them separately.



r2g_internal "$@" 1> stdout.txt 2> stderr.txt
cat stderr.txt | ( while read line; do echo "r2g error: $line"; done )
cat stdout.txt | ( while read line; do echo "r2g: $line"; done )






share|improve this answer













share|improve this answer



share|improve this answer











answered May 9 at 10:55









John Doe

804




804







  • 1




    Note that using process substitution (>(...)) is exactly what he wants to be doing to filter the output from r2g_internal as it arrives.
    – Kusalananda
    May 9 at 15:24











  • Although process substitution is available only in ksh bash zsh -- and bash not when POSIX mode, which may be the cause of the error message. Cf unix.stackexchange.com/questions/309547/…
    – dave_thompson_085
    May 10 at 6:47











  • well it says it's sh that is barfing on the syntax
    – Alexander Mills
    May 19 at 7:58












  • 1




    Note that using process substitution (>(...)) is exactly what he wants to be doing to filter the output from r2g_internal as it arrives.
    – Kusalananda
    May 9 at 15:24











  • Although process substitution is available only in ksh bash zsh -- and bash not when POSIX mode, which may be the cause of the error message. Cf unix.stackexchange.com/questions/309547/…
    – dave_thompson_085
    May 10 at 6:47











  • well it says it's sh that is barfing on the syntax
    – Alexander Mills
    May 19 at 7:58







1




1




Note that using process substitution (>(...)) is exactly what he wants to be doing to filter the output from r2g_internal as it arrives.
– Kusalananda
May 9 at 15:24





Note that using process substitution (>(...)) is exactly what he wants to be doing to filter the output from r2g_internal as it arrives.
– Kusalananda
May 9 at 15:24













Although process substitution is available only in ksh bash zsh -- and bash not when POSIX mode, which may be the cause of the error message. Cf unix.stackexchange.com/questions/309547/…
– dave_thompson_085
May 10 at 6:47





Although process substitution is available only in ksh bash zsh -- and bash not when POSIX mode, which may be the cause of the error message. Cf unix.stackexchange.com/questions/309547/…
– dave_thompson_085
May 10 at 6:47













well it says it's sh that is barfing on the syntax
– Alexander Mills
May 19 at 7:58




well it says it's sh that is barfing on the syntax
– Alexander Mills
May 19 at 7:58












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442660%2fsh-is-evaluating-bash-code-from-parent-shell-and-breaking-down%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?