how to use pipe (concatnate cmd) [closed]

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











up vote
-8
down vote

favorite












i am having trouble to execute "|" command in root mode, the command is as follows



cat xyz.sh | chmod 744 xyz.sh | echo "hello" > xyz.sh


and when i run this command using ./xyz.sh, an error occurs



./xyz.sh: line 1: hello: command not found


please specify me. If, i am doing something wrong with reason!







share|improve this question














closed as unclear what you're asking by roaima, Hauke Laging, G-Man, Jeff Schaller, Michael Homer Mar 25 at 3:46


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 3




    What are you trying to accomplish with that one-liner? Maybe I'm missing something but in its current state it doesn't make sense to me.
    – nxnev
    Mar 24 at 21:37







  • 2




    That command doesn't make any sense whatsoever. What are you trying to achieve?
    – roaima
    Mar 24 at 21:42










  • I just wanted to know, why command not found error is coming even the output is generated!
    – Shakti Shrivas
    Mar 24 at 21:44










  • But it doesn't make sense. Tell us what you're trying to do and you'll get some help that may also explain the "command not found".
    – roaima
    Mar 24 at 21:47






  • 2




    echo "hello" > xyz.sh does not "pass some argument in it", it overwrites the file's contents with the word hello. It should be obvious why ./xyz.sh then produces the error line 1: hello: command not found
    – steeldriver
    Mar 24 at 22:05














up vote
-8
down vote

favorite












i am having trouble to execute "|" command in root mode, the command is as follows



cat xyz.sh | chmod 744 xyz.sh | echo "hello" > xyz.sh


and when i run this command using ./xyz.sh, an error occurs



./xyz.sh: line 1: hello: command not found


please specify me. If, i am doing something wrong with reason!







share|improve this question














closed as unclear what you're asking by roaima, Hauke Laging, G-Man, Jeff Schaller, Michael Homer Mar 25 at 3:46


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 3




    What are you trying to accomplish with that one-liner? Maybe I'm missing something but in its current state it doesn't make sense to me.
    – nxnev
    Mar 24 at 21:37







  • 2




    That command doesn't make any sense whatsoever. What are you trying to achieve?
    – roaima
    Mar 24 at 21:42










  • I just wanted to know, why command not found error is coming even the output is generated!
    – Shakti Shrivas
    Mar 24 at 21:44










  • But it doesn't make sense. Tell us what you're trying to do and you'll get some help that may also explain the "command not found".
    – roaima
    Mar 24 at 21:47






  • 2




    echo "hello" > xyz.sh does not "pass some argument in it", it overwrites the file's contents with the word hello. It should be obvious why ./xyz.sh then produces the error line 1: hello: command not found
    – steeldriver
    Mar 24 at 22:05












up vote
-8
down vote

favorite









up vote
-8
down vote

favorite











i am having trouble to execute "|" command in root mode, the command is as follows



cat xyz.sh | chmod 744 xyz.sh | echo "hello" > xyz.sh


and when i run this command using ./xyz.sh, an error occurs



./xyz.sh: line 1: hello: command not found


please specify me. If, i am doing something wrong with reason!







share|improve this question














i am having trouble to execute "|" command in root mode, the command is as follows



cat xyz.sh | chmod 744 xyz.sh | echo "hello" > xyz.sh


and when i run this command using ./xyz.sh, an error occurs



./xyz.sh: line 1: hello: command not found


please specify me. If, i am doing something wrong with reason!









share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 0:22









terdon♦

122k28229400




122k28229400










asked Mar 24 at 20:48









Shakti Shrivas

1




1




closed as unclear what you're asking by roaima, Hauke Laging, G-Man, Jeff Schaller, Michael Homer Mar 25 at 3:46


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by roaima, Hauke Laging, G-Man, Jeff Schaller, Michael Homer Mar 25 at 3:46


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 3




    What are you trying to accomplish with that one-liner? Maybe I'm missing something but in its current state it doesn't make sense to me.
    – nxnev
    Mar 24 at 21:37







  • 2




    That command doesn't make any sense whatsoever. What are you trying to achieve?
    – roaima
    Mar 24 at 21:42










  • I just wanted to know, why command not found error is coming even the output is generated!
    – Shakti Shrivas
    Mar 24 at 21:44










  • But it doesn't make sense. Tell us what you're trying to do and you'll get some help that may also explain the "command not found".
    – roaima
    Mar 24 at 21:47






  • 2




    echo "hello" > xyz.sh does not "pass some argument in it", it overwrites the file's contents with the word hello. It should be obvious why ./xyz.sh then produces the error line 1: hello: command not found
    – steeldriver
    Mar 24 at 22:05












  • 3




    What are you trying to accomplish with that one-liner? Maybe I'm missing something but in its current state it doesn't make sense to me.
    – nxnev
    Mar 24 at 21:37







  • 2




    That command doesn't make any sense whatsoever. What are you trying to achieve?
    – roaima
    Mar 24 at 21:42










  • I just wanted to know, why command not found error is coming even the output is generated!
    – Shakti Shrivas
    Mar 24 at 21:44










  • But it doesn't make sense. Tell us what you're trying to do and you'll get some help that may also explain the "command not found".
    – roaima
    Mar 24 at 21:47






  • 2




    echo "hello" > xyz.sh does not "pass some argument in it", it overwrites the file's contents with the word hello. It should be obvious why ./xyz.sh then produces the error line 1: hello: command not found
    – steeldriver
    Mar 24 at 22:05







3




3




What are you trying to accomplish with that one-liner? Maybe I'm missing something but in its current state it doesn't make sense to me.
– nxnev
Mar 24 at 21:37





What are you trying to accomplish with that one-liner? Maybe I'm missing something but in its current state it doesn't make sense to me.
– nxnev
Mar 24 at 21:37





2




2




That command doesn't make any sense whatsoever. What are you trying to achieve?
– roaima
Mar 24 at 21:42




That command doesn't make any sense whatsoever. What are you trying to achieve?
– roaima
Mar 24 at 21:42












I just wanted to know, why command not found error is coming even the output is generated!
– Shakti Shrivas
Mar 24 at 21:44




I just wanted to know, why command not found error is coming even the output is generated!
– Shakti Shrivas
Mar 24 at 21:44












But it doesn't make sense. Tell us what you're trying to do and you'll get some help that may also explain the "command not found".
– roaima
Mar 24 at 21:47




But it doesn't make sense. Tell us what you're trying to do and you'll get some help that may also explain the "command not found".
– roaima
Mar 24 at 21:47




2




2




echo "hello" > xyz.sh does not "pass some argument in it", it overwrites the file's contents with the word hello. It should be obvious why ./xyz.sh then produces the error line 1: hello: command not found
– steeldriver
Mar 24 at 22:05




echo "hello" > xyz.sh does not "pass some argument in it", it overwrites the file's contents with the word hello. It should be obvious why ./xyz.sh then produces the error line 1: hello: command not found
– steeldriver
Mar 24 at 22:05










1 Answer
1






active

oldest

votes

















up vote
2
down vote













First, you need to understand what a pipeline is:




A pipeline is a sequence of one or more commands separated by the control operator |. For each command but the last, the shell shall connect the standard output of the command to the standard input of the next command




What happens in your pipeline is the following:




  1. cat sends the content of xyz.sh to the standard input of the next command.


  2. chmod receives that data but, AFAIK, it doesn't do anything with it. Instead, it changes the permissions of xyz.sh and sends nothing to the standard input of the next command.


  3. echo receives nothing but it doesn't matter because echo doesn't read standard input in the first place. As steeldriver said, echo overwrites the content of xyz.sh with the word hello.

Then, if you try to run xyz.sh, the only statement your shell finds is hello and it will try to run hello as a command. You don't have any hello command installed, so that's why you get the command not found error.






share|improve this answer



























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    First, you need to understand what a pipeline is:




    A pipeline is a sequence of one or more commands separated by the control operator |. For each command but the last, the shell shall connect the standard output of the command to the standard input of the next command




    What happens in your pipeline is the following:




    1. cat sends the content of xyz.sh to the standard input of the next command.


    2. chmod receives that data but, AFAIK, it doesn't do anything with it. Instead, it changes the permissions of xyz.sh and sends nothing to the standard input of the next command.


    3. echo receives nothing but it doesn't matter because echo doesn't read standard input in the first place. As steeldriver said, echo overwrites the content of xyz.sh with the word hello.

    Then, if you try to run xyz.sh, the only statement your shell finds is hello and it will try to run hello as a command. You don't have any hello command installed, so that's why you get the command not found error.






    share|improve this answer
























      up vote
      2
      down vote













      First, you need to understand what a pipeline is:




      A pipeline is a sequence of one or more commands separated by the control operator |. For each command but the last, the shell shall connect the standard output of the command to the standard input of the next command




      What happens in your pipeline is the following:




      1. cat sends the content of xyz.sh to the standard input of the next command.


      2. chmod receives that data but, AFAIK, it doesn't do anything with it. Instead, it changes the permissions of xyz.sh and sends nothing to the standard input of the next command.


      3. echo receives nothing but it doesn't matter because echo doesn't read standard input in the first place. As steeldriver said, echo overwrites the content of xyz.sh with the word hello.

      Then, if you try to run xyz.sh, the only statement your shell finds is hello and it will try to run hello as a command. You don't have any hello command installed, so that's why you get the command not found error.






      share|improve this answer






















        up vote
        2
        down vote










        up vote
        2
        down vote









        First, you need to understand what a pipeline is:




        A pipeline is a sequence of one or more commands separated by the control operator |. For each command but the last, the shell shall connect the standard output of the command to the standard input of the next command




        What happens in your pipeline is the following:




        1. cat sends the content of xyz.sh to the standard input of the next command.


        2. chmod receives that data but, AFAIK, it doesn't do anything with it. Instead, it changes the permissions of xyz.sh and sends nothing to the standard input of the next command.


        3. echo receives nothing but it doesn't matter because echo doesn't read standard input in the first place. As steeldriver said, echo overwrites the content of xyz.sh with the word hello.

        Then, if you try to run xyz.sh, the only statement your shell finds is hello and it will try to run hello as a command. You don't have any hello command installed, so that's why you get the command not found error.






        share|improve this answer












        First, you need to understand what a pipeline is:




        A pipeline is a sequence of one or more commands separated by the control operator |. For each command but the last, the shell shall connect the standard output of the command to the standard input of the next command




        What happens in your pipeline is the following:




        1. cat sends the content of xyz.sh to the standard input of the next command.


        2. chmod receives that data but, AFAIK, it doesn't do anything with it. Instead, it changes the permissions of xyz.sh and sends nothing to the standard input of the next command.


        3. echo receives nothing but it doesn't matter because echo doesn't read standard input in the first place. As steeldriver said, echo overwrites the content of xyz.sh with the word hello.

        Then, if you try to run xyz.sh, the only statement your shell finds is hello and it will try to run hello as a command. You don't have any hello command installed, so that's why you get the command not found error.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 22:30









        nxnev

        2,4522423




        2,4522423












            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)