Misunderstanding the purpose of a process substitution

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











up vote
1
down vote

favorite












I guess I'm missing some understanding on the use cases of a process substitution. My intuition was that a process substitution, of the form <(COMMANDS) would execute COMMANDS and then feed the result of the program into whatever command it's a part of, so command1 <(command2) would evaluate command2 and pass the result as the first argument into command1.



I thought the following would've worked:



$ for i in <(cat list.txt); do echo $i; done


where list.txt is a file containing a list of words (separated by newlines). When I run this, it simply outputs /dev/fd/63, which I can only assume is like a temporary pathname to the output of the subshell created in the process substitution?



I thought the above would've worked, because it works fine when I write



$ for i in `cat list.txt`; do echo $i; done


I've never seen this ` notation before, what does it mean exactly? And what understanding am I lacking about process substitutions?







share|improve this question


























    up vote
    1
    down vote

    favorite












    I guess I'm missing some understanding on the use cases of a process substitution. My intuition was that a process substitution, of the form <(COMMANDS) would execute COMMANDS and then feed the result of the program into whatever command it's a part of, so command1 <(command2) would evaluate command2 and pass the result as the first argument into command1.



    I thought the following would've worked:



    $ for i in <(cat list.txt); do echo $i; done


    where list.txt is a file containing a list of words (separated by newlines). When I run this, it simply outputs /dev/fd/63, which I can only assume is like a temporary pathname to the output of the subshell created in the process substitution?



    I thought the above would've worked, because it works fine when I write



    $ for i in `cat list.txt`; do echo $i; done


    I've never seen this ` notation before, what does it mean exactly? And what understanding am I lacking about process substitutions?







    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I guess I'm missing some understanding on the use cases of a process substitution. My intuition was that a process substitution, of the form <(COMMANDS) would execute COMMANDS and then feed the result of the program into whatever command it's a part of, so command1 <(command2) would evaluate command2 and pass the result as the first argument into command1.



      I thought the following would've worked:



      $ for i in <(cat list.txt); do echo $i; done


      where list.txt is a file containing a list of words (separated by newlines). When I run this, it simply outputs /dev/fd/63, which I can only assume is like a temporary pathname to the output of the subshell created in the process substitution?



      I thought the above would've worked, because it works fine when I write



      $ for i in `cat list.txt`; do echo $i; done


      I've never seen this ` notation before, what does it mean exactly? And what understanding am I lacking about process substitutions?







      share|improve this question














      I guess I'm missing some understanding on the use cases of a process substitution. My intuition was that a process substitution, of the form <(COMMANDS) would execute COMMANDS and then feed the result of the program into whatever command it's a part of, so command1 <(command2) would evaluate command2 and pass the result as the first argument into command1.



      I thought the following would've worked:



      $ for i in <(cat list.txt); do echo $i; done


      where list.txt is a file containing a list of words (separated by newlines). When I run this, it simply outputs /dev/fd/63, which I can only assume is like a temporary pathname to the output of the subshell created in the process substitution?



      I thought the above would've worked, because it works fine when I write



      $ for i in `cat list.txt`; do echo $i; done


      I've never seen this ` notation before, what does it mean exactly? And what understanding am I lacking about process substitutions?









      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 20 at 22:33









      Rui F Ribeiro

      35k1269113




      35k1269113










      asked Feb 9 at 2:01









      user3002473

      1184




      1184




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          6
          down vote



          accepted










          `foo` is command substitution, not process substitution. $(foo) is also command substitution, and is the preferred form since it is easier to use nested command substitution: $(foo1 $(foo2 $(foo3 ...))).



          With command substitution, `foo`/$(foo), the output of foo is used as words in the command line. So for in $(echo a b c) becomes as if you'd used for i in a b c instead. The command in the command substitution is executed first, its output obtained, and then the output is used to create the next command line, which is then executed, and so on. Field splitting, wildcard expansion, etc. happen, so quoting is an important consideration in command substitution.



          With process substitution, <(foo)/>(foo), the stdin/stdout of the process is provided as a file, so cat <(foo) becomes as if you'd used foo > /some/file and cat /some/file, and tee >(foo) becomes as if you'd done tee /some/file and foo < /some/file. The commands are executed concurrently. Since the output is not seen by the shell, field splitting and wildcard expansion are not a concern.






          share|improve this answer






















            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%2f422958%2fmisunderstanding-the-purpose-of-a-process-substitution%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
            6
            down vote



            accepted










            `foo` is command substitution, not process substitution. $(foo) is also command substitution, and is the preferred form since it is easier to use nested command substitution: $(foo1 $(foo2 $(foo3 ...))).



            With command substitution, `foo`/$(foo), the output of foo is used as words in the command line. So for in $(echo a b c) becomes as if you'd used for i in a b c instead. The command in the command substitution is executed first, its output obtained, and then the output is used to create the next command line, which is then executed, and so on. Field splitting, wildcard expansion, etc. happen, so quoting is an important consideration in command substitution.



            With process substitution, <(foo)/>(foo), the stdin/stdout of the process is provided as a file, so cat <(foo) becomes as if you'd used foo > /some/file and cat /some/file, and tee >(foo) becomes as if you'd done tee /some/file and foo < /some/file. The commands are executed concurrently. Since the output is not seen by the shell, field splitting and wildcard expansion are not a concern.






            share|improve this answer


























              up vote
              6
              down vote



              accepted










              `foo` is command substitution, not process substitution. $(foo) is also command substitution, and is the preferred form since it is easier to use nested command substitution: $(foo1 $(foo2 $(foo3 ...))).



              With command substitution, `foo`/$(foo), the output of foo is used as words in the command line. So for in $(echo a b c) becomes as if you'd used for i in a b c instead. The command in the command substitution is executed first, its output obtained, and then the output is used to create the next command line, which is then executed, and so on. Field splitting, wildcard expansion, etc. happen, so quoting is an important consideration in command substitution.



              With process substitution, <(foo)/>(foo), the stdin/stdout of the process is provided as a file, so cat <(foo) becomes as if you'd used foo > /some/file and cat /some/file, and tee >(foo) becomes as if you'd done tee /some/file and foo < /some/file. The commands are executed concurrently. Since the output is not seen by the shell, field splitting and wildcard expansion are not a concern.






              share|improve this answer
























                up vote
                6
                down vote



                accepted







                up vote
                6
                down vote



                accepted






                `foo` is command substitution, not process substitution. $(foo) is also command substitution, and is the preferred form since it is easier to use nested command substitution: $(foo1 $(foo2 $(foo3 ...))).



                With command substitution, `foo`/$(foo), the output of foo is used as words in the command line. So for in $(echo a b c) becomes as if you'd used for i in a b c instead. The command in the command substitution is executed first, its output obtained, and then the output is used to create the next command line, which is then executed, and so on. Field splitting, wildcard expansion, etc. happen, so quoting is an important consideration in command substitution.



                With process substitution, <(foo)/>(foo), the stdin/stdout of the process is provided as a file, so cat <(foo) becomes as if you'd used foo > /some/file and cat /some/file, and tee >(foo) becomes as if you'd done tee /some/file and foo < /some/file. The commands are executed concurrently. Since the output is not seen by the shell, field splitting and wildcard expansion are not a concern.






                share|improve this answer














                `foo` is command substitution, not process substitution. $(foo) is also command substitution, and is the preferred form since it is easier to use nested command substitution: $(foo1 $(foo2 $(foo3 ...))).



                With command substitution, `foo`/$(foo), the output of foo is used as words in the command line. So for in $(echo a b c) becomes as if you'd used for i in a b c instead. The command in the command substitution is executed first, its output obtained, and then the output is used to create the next command line, which is then executed, and so on. Field splitting, wildcard expansion, etc. happen, so quoting is an important consideration in command substitution.



                With process substitution, <(foo)/>(foo), the stdin/stdout of the process is provided as a file, so cat <(foo) becomes as if you'd used foo > /some/file and cat /some/file, and tee >(foo) becomes as if you'd done tee /some/file and foo < /some/file. The commands are executed concurrently. Since the output is not seen by the shell, field splitting and wildcard expansion are not a concern.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Feb 9 at 2:40

























                answered Feb 9 at 2:26









                muru

                33.4k577142




                33.4k577142






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f422958%2fmisunderstanding-the-purpose-of-a-process-substitution%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?