How can I know if a command works with pipe?











up vote
2
down vote

favorite












I saw this command:



docker inspect --format '{{.State.Running}}' $(docker ps -lq)


and this:



docker ps -l -q|while read cid b; do docker inspect -f '{{ .State.Running }}' $cid; done;


My question is why it cannot be written as:



docker ps -l -q|docker inspect -f '{{.State.Running}}'


If that was because docker inspect does not work with pipe, how can I know which command can and which cannot?










share|improve this question




























    up vote
    2
    down vote

    favorite












    I saw this command:



    docker inspect --format '{{.State.Running}}' $(docker ps -lq)


    and this:



    docker ps -l -q|while read cid b; do docker inspect -f '{{ .State.Running }}' $cid; done;


    My question is why it cannot be written as:



    docker ps -l -q|docker inspect -f '{{.State.Running}}'


    If that was because docker inspect does not work with pipe, how can I know which command can and which cannot?










    share|improve this question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I saw this command:



      docker inspect --format '{{.State.Running}}' $(docker ps -lq)


      and this:



      docker ps -l -q|while read cid b; do docker inspect -f '{{ .State.Running }}' $cid; done;


      My question is why it cannot be written as:



      docker ps -l -q|docker inspect -f '{{.State.Running}}'


      If that was because docker inspect does not work with pipe, how can I know which command can and which cannot?










      share|improve this question















      I saw this command:



      docker inspect --format '{{.State.Running}}' $(docker ps -lq)


      and this:



      docker ps -l -q|while read cid b; do docker inspect -f '{{ .State.Running }}' $cid; done;


      My question is why it cannot be written as:



      docker ps -l -q|docker inspect -f '{{.State.Running}}'


      If that was because docker inspect does not work with pipe, how can I know which command can and which cannot?







      pipe docker






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 25 at 15:00









      Rui F Ribeiro

      38.3k1475126




      38.3k1475126










      asked Oct 2 '15 at 10:59









      Xiao Peng - ZenUML.com

      1214




      1214






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          Pipe takes the output of the first program and passes it into the next program. In a sense, it pretends to be a user typing input into the second program in a terminal. So, if you can run the program and type in (for example) a list of files to operate on while the program is running, then you can do the same thing with a pipe.



          You may see hints to what can be done using pipes in a program's manual. For instance, man wget mentions the -i argument, and that -i - will read files from standard input, also called STDIN. So you could cat list-of-links.txt | wget -i -, or more effectively wget -i - < list-of-links.txt.






          share|improve this answer





















          • A caveat to this is that some programs acts differently when the input comes from or goes to a pipe, compared from when connected to a terminal.
            – Kusalananda
            Nov 25 at 15:03













          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: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          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%2f233470%2fhow-can-i-know-if-a-command-works-with-pipe%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote













          Pipe takes the output of the first program and passes it into the next program. In a sense, it pretends to be a user typing input into the second program in a terminal. So, if you can run the program and type in (for example) a list of files to operate on while the program is running, then you can do the same thing with a pipe.



          You may see hints to what can be done using pipes in a program's manual. For instance, man wget mentions the -i argument, and that -i - will read files from standard input, also called STDIN. So you could cat list-of-links.txt | wget -i -, or more effectively wget -i - < list-of-links.txt.






          share|improve this answer





















          • A caveat to this is that some programs acts differently when the input comes from or goes to a pipe, compared from when connected to a terminal.
            – Kusalananda
            Nov 25 at 15:03

















          up vote
          2
          down vote













          Pipe takes the output of the first program and passes it into the next program. In a sense, it pretends to be a user typing input into the second program in a terminal. So, if you can run the program and type in (for example) a list of files to operate on while the program is running, then you can do the same thing with a pipe.



          You may see hints to what can be done using pipes in a program's manual. For instance, man wget mentions the -i argument, and that -i - will read files from standard input, also called STDIN. So you could cat list-of-links.txt | wget -i -, or more effectively wget -i - < list-of-links.txt.






          share|improve this answer





















          • A caveat to this is that some programs acts differently when the input comes from or goes to a pipe, compared from when connected to a terminal.
            – Kusalananda
            Nov 25 at 15:03















          up vote
          2
          down vote










          up vote
          2
          down vote









          Pipe takes the output of the first program and passes it into the next program. In a sense, it pretends to be a user typing input into the second program in a terminal. So, if you can run the program and type in (for example) a list of files to operate on while the program is running, then you can do the same thing with a pipe.



          You may see hints to what can be done using pipes in a program's manual. For instance, man wget mentions the -i argument, and that -i - will read files from standard input, also called STDIN. So you could cat list-of-links.txt | wget -i -, or more effectively wget -i - < list-of-links.txt.






          share|improve this answer












          Pipe takes the output of the first program and passes it into the next program. In a sense, it pretends to be a user typing input into the second program in a terminal. So, if you can run the program and type in (for example) a list of files to operate on while the program is running, then you can do the same thing with a pipe.



          You may see hints to what can be done using pipes in a program's manual. For instance, man wget mentions the -i argument, and that -i - will read files from standard input, also called STDIN. So you could cat list-of-links.txt | wget -i -, or more effectively wget -i - < list-of-links.txt.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Oct 2 '15 at 11:25









          tripflag

          43524




          43524












          • A caveat to this is that some programs acts differently when the input comes from or goes to a pipe, compared from when connected to a terminal.
            – Kusalananda
            Nov 25 at 15:03




















          • A caveat to this is that some programs acts differently when the input comes from or goes to a pipe, compared from when connected to a terminal.
            – Kusalananda
            Nov 25 at 15:03


















          A caveat to this is that some programs acts differently when the input comes from or goes to a pipe, compared from when connected to a terminal.
          – Kusalananda
          Nov 25 at 15:03






          A caveat to this is that some programs acts differently when the input comes from or goes to a pipe, compared from when connected to a terminal.
          – Kusalananda
          Nov 25 at 15:03




















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f233470%2fhow-can-i-know-if-a-command-works-with-pipe%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Accessing regular linux commands in Huawei's Dopra Linux

          Can't connect RFCOMM socket: Host is down

          Kernel panic - not syncing: Fatal Exception in Interrupt