how to use pipe (concatnate cmd) [closed]

Clash 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!
shell-script
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.
 |Â
show 3 more comments
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!
shell-script
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.shdoes not "pass some argument in it", it overwrites the file's contents with the wordhello. It should be obvious why./xyz.shthen produces the errorline 1: hello: command not found
â steeldriver
Mar 24 at 22:05
 |Â
show 3 more comments
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!
shell-script
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!
shell-script
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.shdoes not "pass some argument in it", it overwrites the file's contents with the wordhello. It should be obvious why./xyz.shthen produces the errorline 1: hello: command not found
â steeldriver
Mar 24 at 22:05
 |Â
show 3 more comments
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.shdoes not "pass some argument in it", it overwrites the file's contents with the wordhello. It should be obvious why./xyz.shthen produces the errorline 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
 |Â
show 3 more comments
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:
catsends the content ofxyz.shto the standard input of the next command.chmodreceives that data but, AFAIK, it doesn't do anything with it. Instead, it changes the permissions ofxyz.shand sends nothing to the standard input of the next command.echoreceives nothing but it doesn't matter becauseechodoesn't read standard input in the first place. As steeldriver said,echooverwrites the content ofxyz.shwith the wordhello.
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.
add a comment |Â
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:
catsends the content ofxyz.shto the standard input of the next command.chmodreceives that data but, AFAIK, it doesn't do anything with it. Instead, it changes the permissions ofxyz.shand sends nothing to the standard input of the next command.echoreceives nothing but it doesn't matter becauseechodoesn't read standard input in the first place. As steeldriver said,echooverwrites the content ofxyz.shwith the wordhello.
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.
add a comment |Â
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:
catsends the content ofxyz.shto the standard input of the next command.chmodreceives that data but, AFAIK, it doesn't do anything with it. Instead, it changes the permissions ofxyz.shand sends nothing to the standard input of the next command.echoreceives nothing but it doesn't matter becauseechodoesn't read standard input in the first place. As steeldriver said,echooverwrites the content ofxyz.shwith the wordhello.
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.
add a comment |Â
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:
catsends the content ofxyz.shto the standard input of the next command.chmodreceives that data but, AFAIK, it doesn't do anything with it. Instead, it changes the permissions ofxyz.shand sends nothing to the standard input of the next command.echoreceives nothing but it doesn't matter becauseechodoesn't read standard input in the first place. As steeldriver said,echooverwrites the content ofxyz.shwith the wordhello.
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.
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:
catsends the content ofxyz.shto the standard input of the next command.chmodreceives that data but, AFAIK, it doesn't do anything with it. Instead, it changes the permissions ofxyz.shand sends nothing to the standard input of the next command.echoreceives nothing but it doesn't matter becauseechodoesn't read standard input in the first place. As steeldriver said,echooverwrites the content ofxyz.shwith the wordhello.
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.
answered Mar 24 at 22:30
nxnev
2,4522423
2,4522423
add a comment |Â
add a comment |Â
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.shdoes not "pass some argument in it", it overwrites the file's contents with the wordhello. It should be obvious why./xyz.shthen produces the errorline 1: hello: command not foundâ steeldriver
Mar 24 at 22:05