why is `test.sh & | test.sh` wrongUse & (ampersand) in single line bash loopWhat's meaning the of a...

Multi tool use
Multi tool use

How to trick the reader into thinking they're following a redshirt instead of the protagonist?

You have (3^2 + 2^3 + 2^2) Guesses Left. Figure out the Last one

Why can I traceroute to this IP address, but not ping?

How to handle (one's own) self-harm scars (on the arm), in a work environment?

What aircraft was used as Air Force One for the flight between Southampton and Shannon?

Is it possible to fly backward if you have a 'really strong' headwind?

How to ensure color fidelity of the same file on two computers?

What is the maximum number of net attacks that one can make in a round?

sed + add word before string only if not exists

60s or 70s novel about Empire of Man making 1st contact with 1st discovered alien race

Heap allocation on microcontroller

Active low-pass filters --- good to what frequencies?

Does the Long March-11 increase its thrust after clearing the launch tower?

Is using 'echo' to display attacker-controlled data on the terminal dangerous?

How can I search for all contacts without email?

Teaching a class likely meant to inflate the GPA of student athletes

Are there any important biographies of nobodies?

If I leave the US through an airport, do I have to return through the same airport?

Why does logistic function use e rather than 2?

Meaning of 'lose their grip on the groins of their followers'

Why we don’t make use of the t-distribution for constructing a confidence interval for a proportion?

Russian word for a male zebra

How come the nude protesters were not arrested?

Is an entry level DSLR going to shoot nice portrait pictures?



why is `test.sh & | test.sh` wrong


Use & (ampersand) in single line bash loopWhat's meaning the of a pair of parentheses after a string literal?Why isn't this `expr … | bc -l` command working?For loop brackets - C like syntaxWhy is this simple bash script throwing an error on if/then/else?Why Can't I Call Two Aliases With “;”?Syntax error near unexpected token `done'Comparing two integer variablesCan't figure out “Syntax error near unexpected token `done'” issueError when run multiple commands in one line in bash






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I have a bash script named test.sh as below:



#!/bin/bash

while :
do
echo xxx
sleep 1
done


I don't know why ./test.sh & | ./test.sh gives me an error: -bash: syntax error near unexpected token |', whereas ./test.sh | ./test.sh and ./test.sh | ./test.sh & work.










share|improve this question























  • @NasirRiley nope, it's perfectly fine to run it in the background: { echo yup & } | cat or { ./test.sh & } | ./test.sh are fine. It's just a limitation of the grammar.

    – mosvy
    38 mins ago













  • @mosvy That isn't the same thing. If you remove the curly brackets then the error occurs with either of those commands. In the context that he's trying to run it, it's going to return that error which is why it doesn't occur when the ampersand is removed.

    – Nasir Riley
    33 mins ago











  • @NasirRiley do you mean that { a & } | b won't run a in the background? It will.

    – mosvy
    29 mins ago











  • BTW, the full shell grammar is here. It's obvious from following the productions that you cannot write a & | b, but that doesn't mean that you can't pipe the output of a bg command to a fg command. You can do that fine. Just add some extra braces.

    – mosvy
    26 mins ago











  • @mosvy That literal command wouldn't run anywhere because a and b are not commands unless you've set an alias to something(I'm joking). What I mean is that the way that it functions is not the same. Perhaps I should delete my previous comment to clarify what I actually mean.

    – Nasir Riley
    25 mins ago


















0















I have a bash script named test.sh as below:



#!/bin/bash

while :
do
echo xxx
sleep 1
done


I don't know why ./test.sh & | ./test.sh gives me an error: -bash: syntax error near unexpected token |', whereas ./test.sh | ./test.sh and ./test.sh | ./test.sh & work.










share|improve this question























  • @NasirRiley nope, it's perfectly fine to run it in the background: { echo yup & } | cat or { ./test.sh & } | ./test.sh are fine. It's just a limitation of the grammar.

    – mosvy
    38 mins ago













  • @mosvy That isn't the same thing. If you remove the curly brackets then the error occurs with either of those commands. In the context that he's trying to run it, it's going to return that error which is why it doesn't occur when the ampersand is removed.

    – Nasir Riley
    33 mins ago











  • @NasirRiley do you mean that { a & } | b won't run a in the background? It will.

    – mosvy
    29 mins ago











  • BTW, the full shell grammar is here. It's obvious from following the productions that you cannot write a & | b, but that doesn't mean that you can't pipe the output of a bg command to a fg command. You can do that fine. Just add some extra braces.

    – mosvy
    26 mins ago











  • @mosvy That literal command wouldn't run anywhere because a and b are not commands unless you've set an alias to something(I'm joking). What I mean is that the way that it functions is not the same. Perhaps I should delete my previous comment to clarify what I actually mean.

    – Nasir Riley
    25 mins ago














0












0








0








I have a bash script named test.sh as below:



#!/bin/bash

while :
do
echo xxx
sleep 1
done


I don't know why ./test.sh & | ./test.sh gives me an error: -bash: syntax error near unexpected token |', whereas ./test.sh | ./test.sh and ./test.sh | ./test.sh & work.










share|improve this question














I have a bash script named test.sh as below:



#!/bin/bash

while :
do
echo xxx
sleep 1
done


I don't know why ./test.sh & | ./test.sh gives me an error: -bash: syntax error near unexpected token |', whereas ./test.sh | ./test.sh and ./test.sh | ./test.sh & work.







bash pipe






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 50 mins ago









YvesYves

9891025




9891025













  • @NasirRiley nope, it's perfectly fine to run it in the background: { echo yup & } | cat or { ./test.sh & } | ./test.sh are fine. It's just a limitation of the grammar.

    – mosvy
    38 mins ago













  • @mosvy That isn't the same thing. If you remove the curly brackets then the error occurs with either of those commands. In the context that he's trying to run it, it's going to return that error which is why it doesn't occur when the ampersand is removed.

    – Nasir Riley
    33 mins ago











  • @NasirRiley do you mean that { a & } | b won't run a in the background? It will.

    – mosvy
    29 mins ago











  • BTW, the full shell grammar is here. It's obvious from following the productions that you cannot write a & | b, but that doesn't mean that you can't pipe the output of a bg command to a fg command. You can do that fine. Just add some extra braces.

    – mosvy
    26 mins ago











  • @mosvy That literal command wouldn't run anywhere because a and b are not commands unless you've set an alias to something(I'm joking). What I mean is that the way that it functions is not the same. Perhaps I should delete my previous comment to clarify what I actually mean.

    – Nasir Riley
    25 mins ago



















  • @NasirRiley nope, it's perfectly fine to run it in the background: { echo yup & } | cat or { ./test.sh & } | ./test.sh are fine. It's just a limitation of the grammar.

    – mosvy
    38 mins ago













  • @mosvy That isn't the same thing. If you remove the curly brackets then the error occurs with either of those commands. In the context that he's trying to run it, it's going to return that error which is why it doesn't occur when the ampersand is removed.

    – Nasir Riley
    33 mins ago











  • @NasirRiley do you mean that { a & } | b won't run a in the background? It will.

    – mosvy
    29 mins ago











  • BTW, the full shell grammar is here. It's obvious from following the productions that you cannot write a & | b, but that doesn't mean that you can't pipe the output of a bg command to a fg command. You can do that fine. Just add some extra braces.

    – mosvy
    26 mins ago











  • @mosvy That literal command wouldn't run anywhere because a and b are not commands unless you've set an alias to something(I'm joking). What I mean is that the way that it functions is not the same. Perhaps I should delete my previous comment to clarify what I actually mean.

    – Nasir Riley
    25 mins ago

















@NasirRiley nope, it's perfectly fine to run it in the background: { echo yup & } | cat or { ./test.sh & } | ./test.sh are fine. It's just a limitation of the grammar.

– mosvy
38 mins ago







@NasirRiley nope, it's perfectly fine to run it in the background: { echo yup & } | cat or { ./test.sh & } | ./test.sh are fine. It's just a limitation of the grammar.

– mosvy
38 mins ago















@mosvy That isn't the same thing. If you remove the curly brackets then the error occurs with either of those commands. In the context that he's trying to run it, it's going to return that error which is why it doesn't occur when the ampersand is removed.

– Nasir Riley
33 mins ago





@mosvy That isn't the same thing. If you remove the curly brackets then the error occurs with either of those commands. In the context that he's trying to run it, it's going to return that error which is why it doesn't occur when the ampersand is removed.

– Nasir Riley
33 mins ago













@NasirRiley do you mean that { a & } | b won't run a in the background? It will.

– mosvy
29 mins ago





@NasirRiley do you mean that { a & } | b won't run a in the background? It will.

– mosvy
29 mins ago













BTW, the full shell grammar is here. It's obvious from following the productions that you cannot write a & | b, but that doesn't mean that you can't pipe the output of a bg command to a fg command. You can do that fine. Just add some extra braces.

– mosvy
26 mins ago





BTW, the full shell grammar is here. It's obvious from following the productions that you cannot write a & | b, but that doesn't mean that you can't pipe the output of a bg command to a fg command. You can do that fine. Just add some extra braces.

– mosvy
26 mins ago













@mosvy That literal command wouldn't run anywhere because a and b are not commands unless you've set an alias to something(I'm joking). What I mean is that the way that it functions is not the same. Perhaps I should delete my previous comment to clarify what I actually mean.

– Nasir Riley
25 mins ago





@mosvy That literal command wouldn't run anywhere because a and b are not commands unless you've set an alias to something(I'm joking). What I mean is that the way that it functions is not the same. Perhaps I should delete my previous comment to clarify what I actually mean.

– Nasir Riley
25 mins ago










0






active

oldest

votes












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',
autoActivateHeartbeat: false,
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%2f523448%2fwhy-is-test-sh-test-sh-wrong%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f523448%2fwhy-is-test-sh-test-sh-wrong%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







x6CttPLdw6K4,EQbBL TZIf1t,gm4TTs73X8l48mfzdKq
5dlPeQbHk1Fx8 t1xEm292Zh9sZC61jn62 QOAcm,MZ yRUYjm I08JJjDP

Popular posts from this blog

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...