Using process substitution, only send stderr to process

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











up vote
0
down vote

favorite
1












I have this:



exec > >( while read line; do echo " stdout: $line"; done )
exec 2> >( while read line; do echo " stderr: $line"; done )

echo "rolo"
>&2 echo "cholo"


if you run that script, it results in the following output:




stdout: rolo

stdout: stderr: cholo




how can I only send stderr to the second process substitution line?
I don't get it.



I don't understand why this is happening:




stdout: rolo

stdout: stderr: cholo # what lol








share|improve this question

























    up vote
    0
    down vote

    favorite
    1












    I have this:



    exec > >( while read line; do echo " stdout: $line"; done )
    exec 2> >( while read line; do echo " stderr: $line"; done )

    echo "rolo"
    >&2 echo "cholo"


    if you run that script, it results in the following output:




    stdout: rolo

    stdout: stderr: cholo




    how can I only send stderr to the second process substitution line?
    I don't get it.



    I don't understand why this is happening:




    stdout: rolo

    stdout: stderr: cholo # what lol








    share|improve this question























      up vote
      0
      down vote

      favorite
      1









      up vote
      0
      down vote

      favorite
      1






      1





      I have this:



      exec > >( while read line; do echo " stdout: $line"; done )
      exec 2> >( while read line; do echo " stderr: $line"; done )

      echo "rolo"
      >&2 echo "cholo"


      if you run that script, it results in the following output:




      stdout: rolo

      stdout: stderr: cholo




      how can I only send stderr to the second process substitution line?
      I don't get it.



      I don't understand why this is happening:




      stdout: rolo

      stdout: stderr: cholo # what lol








      share|improve this question













      I have this:



      exec > >( while read line; do echo " stdout: $line"; done )
      exec 2> >( while read line; do echo " stderr: $line"; done )

      echo "rolo"
      >&2 echo "cholo"


      if you run that script, it results in the following output:




      stdout: rolo

      stdout: stderr: cholo




      how can I only send stderr to the second process substitution line?
      I don't get it.



      I don't understand why this is happening:




      stdout: rolo

      stdout: stderr: cholo # what lol










      share|improve this question












      share|improve this question




      share|improve this question








      edited May 8 at 4:55
























      asked May 8 at 4:48









      Alexander Mills

      1,885929




      1,885929




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          You set up the redirections in the wrong order. The standard output of the second process substitution (which prefixes with stderr:) has its standard output prefixed by the first process substitution, because it was run afterwards.



          Try this instead:



          exec 2> >( while read line; do echo " stderr: $line"; done )
          exec > >( while read line; do echo " stdout: $line"; done )

          echo "rolo"
          echo "cholo" >&2


          This outputs



           stderr: cholo
          stdout: rolo


          which is what I presume you want.






          share|improve this answer





















          • Comments are not for extended discussion; this conversation has been moved to chat.
            – terdon♦
            May 8 at 16:37










          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%2f442461%2fusing-process-substitution-only-send-stderr-to-process%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          You set up the redirections in the wrong order. The standard output of the second process substitution (which prefixes with stderr:) has its standard output prefixed by the first process substitution, because it was run afterwards.



          Try this instead:



          exec 2> >( while read line; do echo " stderr: $line"; done )
          exec > >( while read line; do echo " stdout: $line"; done )

          echo "rolo"
          echo "cholo" >&2


          This outputs



           stderr: cholo
          stdout: rolo


          which is what I presume you want.






          share|improve this answer





















          • Comments are not for extended discussion; this conversation has been moved to chat.
            – terdon♦
            May 8 at 16:37














          up vote
          3
          down vote



          accepted










          You set up the redirections in the wrong order. The standard output of the second process substitution (which prefixes with stderr:) has its standard output prefixed by the first process substitution, because it was run afterwards.



          Try this instead:



          exec 2> >( while read line; do echo " stderr: $line"; done )
          exec > >( while read line; do echo " stdout: $line"; done )

          echo "rolo"
          echo "cholo" >&2


          This outputs



           stderr: cholo
          stdout: rolo


          which is what I presume you want.






          share|improve this answer





















          • Comments are not for extended discussion; this conversation has been moved to chat.
            – terdon♦
            May 8 at 16:37












          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          You set up the redirections in the wrong order. The standard output of the second process substitution (which prefixes with stderr:) has its standard output prefixed by the first process substitution, because it was run afterwards.



          Try this instead:



          exec 2> >( while read line; do echo " stderr: $line"; done )
          exec > >( while read line; do echo " stdout: $line"; done )

          echo "rolo"
          echo "cholo" >&2


          This outputs



           stderr: cholo
          stdout: rolo


          which is what I presume you want.






          share|improve this answer













          You set up the redirections in the wrong order. The standard output of the second process substitution (which prefixes with stderr:) has its standard output prefixed by the first process substitution, because it was run afterwards.



          Try this instead:



          exec 2> >( while read line; do echo " stderr: $line"; done )
          exec > >( while read line; do echo " stdout: $line"; done )

          echo "rolo"
          echo "cholo" >&2


          This outputs



           stderr: cholo
          stdout: rolo


          which is what I presume you want.







          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered May 8 at 5:06









          Kusalananda

          102k13199315




          102k13199315











          • Comments are not for extended discussion; this conversation has been moved to chat.
            – terdon♦
            May 8 at 16:37
















          • Comments are not for extended discussion; this conversation has been moved to chat.
            – terdon♦
            May 8 at 16:37















          Comments are not for extended discussion; this conversation has been moved to chat.
          – terdon♦
          May 8 at 16:37




          Comments are not for extended discussion; this conversation has been moved to chat.
          – terdon♦
          May 8 at 16:37












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442461%2fusing-process-substitution-only-send-stderr-to-process%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?