Process Substitution ECHOS undesirable 'shell prompt'. Can I disable it?Can I process command output just...
Is it a good security practice to force employees hide their employer to avoid being targeted?
Harley Davidson clattering noise from engine, backfire and failure to start
Why can't we feel the Earth's revolution?
What are the advantages of using TLRs to rangefinders?
Should I worry about having my credit pulled multiple times while car shopping?
Placement of positioning lights on A320 winglets
Should I move out from my current apartment before the contract ends to save more money?
How to search for Android apps without ads?
Idiom for 'person who gets violent when drunk"
Background for black and white chart
Opposite of "Concerto Grosso"?
How can this shape perfectly cover a cube?
Dedicated bike GPS computer over smartphone
My parents claim they cannot pay for my college education; what are my options?
Realistic, logical way for men with medieval-era weaponry to compete with much larger and physically stronger foes
In The Incredibles 2, why does Screenslaver's name use a pun on something that doesn't exist in the 1950s pastiche?
Why did the AvroCar fail to fly above 3 feet?
Does "aurea" have the second meaning?
What is the theme of analysis?
Print the phrase "And she said, 'But that's his.'" using only the alphabet
Loop counter not interpreted as number
What is the color associated with lukewarm?
ISP is not hashing the password I log in with online. Should I take any action?
New Site Design!
Process Substitution ECHOS undesirable 'shell prompt'. Can I disable it?
Can I process command output just before sending it to a file (one liner)?cat in process substitution hangs: what is it waiting for?Pipes vs process substitutiongnuplot shell variable substitution and arraysShell script parameter substitutionCombining multiple process substitutionProcess substitution over ssh with sudo in Bash shellSyntax of process substitutionShell script - child - background processImplementation of process substitution, and concurrency in process substitutionConditional process substitutionUsing process substitution, only send stderr to process
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
Bash 4.4.19(1)-release
Using this code because I cannot use pipes.
func() {
in=$(cat)
echo "'this is it: $in'"
}
echo "a string" > >(func)
This Process Substitution unfortunately is printing the prompt along with my string.
user@srv:~$ ./test.sh
user@srv:~$ 'this is it: a string'
This is undesirable for my usage! to say the least!!!
What is desirable is normal behavior like so:
user@srv:~$ ./test.sh
'this is it: a string'
Can I force Process Substitution not to print a shell prompt?
NOTE: I cannot use pipes... it creates other problems for me.
These are the problems it creates:
Can I process command output just before sending it to a file (one liner)?
bash shell-script scripting
|
show 12 more comments
Bash 4.4.19(1)-release
Using this code because I cannot use pipes.
func() {
in=$(cat)
echo "'this is it: $in'"
}
echo "a string" > >(func)
This Process Substitution unfortunately is printing the prompt along with my string.
user@srv:~$ ./test.sh
user@srv:~$ 'this is it: a string'
This is undesirable for my usage! to say the least!!!
What is desirable is normal behavior like so:
user@srv:~$ ./test.sh
'this is it: a string'
Can I force Process Substitution not to print a shell prompt?
NOTE: I cannot use pipes... it creates other problems for me.
These are the problems it creates:
Can I process command output just before sending it to a file (one liner)?
bash shell-script scripting
Your code does not capture your prompt, it captures input. Your prompt is already stored in an environment variable namedPS1though.
– Jesse_b
3 hours ago
when I run echo "'${PS1}'" in the shell, I get '[e]0;u@h: wa]${debian_chroot:+($debian_chroot)}u@h:w$ '
– conanDrum
3 hours ago
when I run echo "'${PS1}'" in the script, i get ''
– conanDrum
3 hours ago
I noticed that. however I would still like to accomplish this undertaking.
– conanDrum
2 hours ago
Could you say a bit more how the actual value of the prompt ends up in your variable? The prompt is written to the shell's standard error output stream. You would have to actually hop through some hoops to capture it...
– Kusalananda♦
1 hour ago
|
show 12 more comments
Bash 4.4.19(1)-release
Using this code because I cannot use pipes.
func() {
in=$(cat)
echo "'this is it: $in'"
}
echo "a string" > >(func)
This Process Substitution unfortunately is printing the prompt along with my string.
user@srv:~$ ./test.sh
user@srv:~$ 'this is it: a string'
This is undesirable for my usage! to say the least!!!
What is desirable is normal behavior like so:
user@srv:~$ ./test.sh
'this is it: a string'
Can I force Process Substitution not to print a shell prompt?
NOTE: I cannot use pipes... it creates other problems for me.
These are the problems it creates:
Can I process command output just before sending it to a file (one liner)?
bash shell-script scripting
Bash 4.4.19(1)-release
Using this code because I cannot use pipes.
func() {
in=$(cat)
echo "'this is it: $in'"
}
echo "a string" > >(func)
This Process Substitution unfortunately is printing the prompt along with my string.
user@srv:~$ ./test.sh
user@srv:~$ 'this is it: a string'
This is undesirable for my usage! to say the least!!!
What is desirable is normal behavior like so:
user@srv:~$ ./test.sh
'this is it: a string'
Can I force Process Substitution not to print a shell prompt?
NOTE: I cannot use pipes... it creates other problems for me.
These are the problems it creates:
Can I process command output just before sending it to a file (one liner)?
bash shell-script scripting
bash shell-script scripting
edited 46 mins ago
conanDrum
asked 3 hours ago
conanDrumconanDrum
576
576
Your code does not capture your prompt, it captures input. Your prompt is already stored in an environment variable namedPS1though.
– Jesse_b
3 hours ago
when I run echo "'${PS1}'" in the shell, I get '[e]0;u@h: wa]${debian_chroot:+($debian_chroot)}u@h:w$ '
– conanDrum
3 hours ago
when I run echo "'${PS1}'" in the script, i get ''
– conanDrum
3 hours ago
I noticed that. however I would still like to accomplish this undertaking.
– conanDrum
2 hours ago
Could you say a bit more how the actual value of the prompt ends up in your variable? The prompt is written to the shell's standard error output stream. You would have to actually hop through some hoops to capture it...
– Kusalananda♦
1 hour ago
|
show 12 more comments
Your code does not capture your prompt, it captures input. Your prompt is already stored in an environment variable namedPS1though.
– Jesse_b
3 hours ago
when I run echo "'${PS1}'" in the shell, I get '[e]0;u@h: wa]${debian_chroot:+($debian_chroot)}u@h:w$ '
– conanDrum
3 hours ago
when I run echo "'${PS1}'" in the script, i get ''
– conanDrum
3 hours ago
I noticed that. however I would still like to accomplish this undertaking.
– conanDrum
2 hours ago
Could you say a bit more how the actual value of the prompt ends up in your variable? The prompt is written to the shell's standard error output stream. You would have to actually hop through some hoops to capture it...
– Kusalananda♦
1 hour ago
Your code does not capture your prompt, it captures input. Your prompt is already stored in an environment variable named
PS1 though.– Jesse_b
3 hours ago
Your code does not capture your prompt, it captures input. Your prompt is already stored in an environment variable named
PS1 though.– Jesse_b
3 hours ago
when I run echo "'${PS1}'" in the shell, I get '[e]0;u@h: wa]${debian_chroot:+($debian_chroot)}u@h:w$ '
– conanDrum
3 hours ago
when I run echo "'${PS1}'" in the shell, I get '[e]0;u@h: wa]${debian_chroot:+($debian_chroot)}u@h:w$ '
– conanDrum
3 hours ago
when I run echo "'${PS1}'" in the script, i get ''
– conanDrum
3 hours ago
when I run echo "'${PS1}'" in the script, i get ''
– conanDrum
3 hours ago
I noticed that. however I would still like to accomplish this undertaking.
– conanDrum
2 hours ago
I noticed that. however I would still like to accomplish this undertaking.
– conanDrum
2 hours ago
Could you say a bit more how the actual value of the prompt ends up in your variable? The prompt is written to the shell's standard error output stream. You would have to actually hop through some hoops to capture it...
– Kusalananda♦
1 hour ago
Could you say a bit more how the actual value of the prompt ends up in your variable? The prompt is written to the shell's standard error output stream. You would have to actually hop through some hoops to capture it...
– Kusalananda♦
1 hour ago
|
show 12 more comments
1 Answer
1
active
oldest
votes
That happens because your script returns before the subprocess from the >(...) process substitution, which runs asynchronously (ie in the background) and will only come to print its stuff after the shell you called your script from already printed its prompt.
The solution is to wait for it; unfortunately, processes run in subshells, etc. are not managed as part of jobs and do not appear in bash's job table, so you'll have to made do with pgrep -P (find-by-parent):
func() {
in=$(cat)
sleep .2
echo "'this is it: $in'"
}
echo "a string" > >(func)
wait $(pgrep -P $$)
(I've added the sleep .2 just to prevent the symptom from spuriously disappearing -- the extra time the pgrep and wait take to run may be enough for the asynchronous process to terminate, too).
Thanks, please give me a moment to check this... Also, Kusalananda mentioned this: "...The prompt is written to the shell's standard error output stream.... – Kusalananda♦ 1 hour ago" Is it an idea maybe to disable the STDERR so that the prompt does not display before the ECHO and then enable it again?
– conanDrum
28 mins ago
Don't hurry ;-) It's not a good idea to disable the stderr because you may miss error messages written to it.
– mosvy
23 mins ago
and of course it is related to my previous question 3 hours ago, but people are too quick to provide unhelpful answers. Thanks for making this clear to me mosvy. here: unix.stackexchange.com/questions/524534/…
– conanDrum
19 mins ago
Thank you mosvy for pointing in the right direction.
– conanDrum
3 mins ago
is it really necessary to sleep .2? it seems enough to just wait $(pgrep -P $$)
– conanDrum
1 min ago
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f524548%2fprocess-substitution-echos-undesirable-shell-prompt-can-i-disable-it%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
That happens because your script returns before the subprocess from the >(...) process substitution, which runs asynchronously (ie in the background) and will only come to print its stuff after the shell you called your script from already printed its prompt.
The solution is to wait for it; unfortunately, processes run in subshells, etc. are not managed as part of jobs and do not appear in bash's job table, so you'll have to made do with pgrep -P (find-by-parent):
func() {
in=$(cat)
sleep .2
echo "'this is it: $in'"
}
echo "a string" > >(func)
wait $(pgrep -P $$)
(I've added the sleep .2 just to prevent the symptom from spuriously disappearing -- the extra time the pgrep and wait take to run may be enough for the asynchronous process to terminate, too).
Thanks, please give me a moment to check this... Also, Kusalananda mentioned this: "...The prompt is written to the shell's standard error output stream.... – Kusalananda♦ 1 hour ago" Is it an idea maybe to disable the STDERR so that the prompt does not display before the ECHO and then enable it again?
– conanDrum
28 mins ago
Don't hurry ;-) It's not a good idea to disable the stderr because you may miss error messages written to it.
– mosvy
23 mins ago
and of course it is related to my previous question 3 hours ago, but people are too quick to provide unhelpful answers. Thanks for making this clear to me mosvy. here: unix.stackexchange.com/questions/524534/…
– conanDrum
19 mins ago
Thank you mosvy for pointing in the right direction.
– conanDrum
3 mins ago
is it really necessary to sleep .2? it seems enough to just wait $(pgrep -P $$)
– conanDrum
1 min ago
add a comment |
That happens because your script returns before the subprocess from the >(...) process substitution, which runs asynchronously (ie in the background) and will only come to print its stuff after the shell you called your script from already printed its prompt.
The solution is to wait for it; unfortunately, processes run in subshells, etc. are not managed as part of jobs and do not appear in bash's job table, so you'll have to made do with pgrep -P (find-by-parent):
func() {
in=$(cat)
sleep .2
echo "'this is it: $in'"
}
echo "a string" > >(func)
wait $(pgrep -P $$)
(I've added the sleep .2 just to prevent the symptom from spuriously disappearing -- the extra time the pgrep and wait take to run may be enough for the asynchronous process to terminate, too).
Thanks, please give me a moment to check this... Also, Kusalananda mentioned this: "...The prompt is written to the shell's standard error output stream.... – Kusalananda♦ 1 hour ago" Is it an idea maybe to disable the STDERR so that the prompt does not display before the ECHO and then enable it again?
– conanDrum
28 mins ago
Don't hurry ;-) It's not a good idea to disable the stderr because you may miss error messages written to it.
– mosvy
23 mins ago
and of course it is related to my previous question 3 hours ago, but people are too quick to provide unhelpful answers. Thanks for making this clear to me mosvy. here: unix.stackexchange.com/questions/524534/…
– conanDrum
19 mins ago
Thank you mosvy for pointing in the right direction.
– conanDrum
3 mins ago
is it really necessary to sleep .2? it seems enough to just wait $(pgrep -P $$)
– conanDrum
1 min ago
add a comment |
That happens because your script returns before the subprocess from the >(...) process substitution, which runs asynchronously (ie in the background) and will only come to print its stuff after the shell you called your script from already printed its prompt.
The solution is to wait for it; unfortunately, processes run in subshells, etc. are not managed as part of jobs and do not appear in bash's job table, so you'll have to made do with pgrep -P (find-by-parent):
func() {
in=$(cat)
sleep .2
echo "'this is it: $in'"
}
echo "a string" > >(func)
wait $(pgrep -P $$)
(I've added the sleep .2 just to prevent the symptom from spuriously disappearing -- the extra time the pgrep and wait take to run may be enough for the asynchronous process to terminate, too).
That happens because your script returns before the subprocess from the >(...) process substitution, which runs asynchronously (ie in the background) and will only come to print its stuff after the shell you called your script from already printed its prompt.
The solution is to wait for it; unfortunately, processes run in subshells, etc. are not managed as part of jobs and do not appear in bash's job table, so you'll have to made do with pgrep -P (find-by-parent):
func() {
in=$(cat)
sleep .2
echo "'this is it: $in'"
}
echo "a string" > >(func)
wait $(pgrep -P $$)
(I've added the sleep .2 just to prevent the symptom from spuriously disappearing -- the extra time the pgrep and wait take to run may be enough for the asynchronous process to terminate, too).
edited 25 mins ago
answered 33 mins ago
mosvymosvy
13.4k21545
13.4k21545
Thanks, please give me a moment to check this... Also, Kusalananda mentioned this: "...The prompt is written to the shell's standard error output stream.... – Kusalananda♦ 1 hour ago" Is it an idea maybe to disable the STDERR so that the prompt does not display before the ECHO and then enable it again?
– conanDrum
28 mins ago
Don't hurry ;-) It's not a good idea to disable the stderr because you may miss error messages written to it.
– mosvy
23 mins ago
and of course it is related to my previous question 3 hours ago, but people are too quick to provide unhelpful answers. Thanks for making this clear to me mosvy. here: unix.stackexchange.com/questions/524534/…
– conanDrum
19 mins ago
Thank you mosvy for pointing in the right direction.
– conanDrum
3 mins ago
is it really necessary to sleep .2? it seems enough to just wait $(pgrep -P $$)
– conanDrum
1 min ago
add a comment |
Thanks, please give me a moment to check this... Also, Kusalananda mentioned this: "...The prompt is written to the shell's standard error output stream.... – Kusalananda♦ 1 hour ago" Is it an idea maybe to disable the STDERR so that the prompt does not display before the ECHO and then enable it again?
– conanDrum
28 mins ago
Don't hurry ;-) It's not a good idea to disable the stderr because you may miss error messages written to it.
– mosvy
23 mins ago
and of course it is related to my previous question 3 hours ago, but people are too quick to provide unhelpful answers. Thanks for making this clear to me mosvy. here: unix.stackexchange.com/questions/524534/…
– conanDrum
19 mins ago
Thank you mosvy for pointing in the right direction.
– conanDrum
3 mins ago
is it really necessary to sleep .2? it seems enough to just wait $(pgrep -P $$)
– conanDrum
1 min ago
Thanks, please give me a moment to check this... Also, Kusalananda mentioned this: "...The prompt is written to the shell's standard error output stream.... – Kusalananda♦ 1 hour ago" Is it an idea maybe to disable the STDERR so that the prompt does not display before the ECHO and then enable it again?
– conanDrum
28 mins ago
Thanks, please give me a moment to check this... Also, Kusalananda mentioned this: "...The prompt is written to the shell's standard error output stream.... – Kusalananda♦ 1 hour ago" Is it an idea maybe to disable the STDERR so that the prompt does not display before the ECHO and then enable it again?
– conanDrum
28 mins ago
Don't hurry ;-) It's not a good idea to disable the stderr because you may miss error messages written to it.
– mosvy
23 mins ago
Don't hurry ;-) It's not a good idea to disable the stderr because you may miss error messages written to it.
– mosvy
23 mins ago
and of course it is related to my previous question 3 hours ago, but people are too quick to provide unhelpful answers. Thanks for making this clear to me mosvy. here: unix.stackexchange.com/questions/524534/…
– conanDrum
19 mins ago
and of course it is related to my previous question 3 hours ago, but people are too quick to provide unhelpful answers. Thanks for making this clear to me mosvy. here: unix.stackexchange.com/questions/524534/…
– conanDrum
19 mins ago
Thank you mosvy for pointing in the right direction.
– conanDrum
3 mins ago
Thank you mosvy for pointing in the right direction.
– conanDrum
3 mins ago
is it really necessary to sleep .2? it seems enough to just wait $(pgrep -P $$)
– conanDrum
1 min ago
is it really necessary to sleep .2? it seems enough to just wait $(pgrep -P $$)
– conanDrum
1 min ago
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f524548%2fprocess-substitution-echos-undesirable-shell-prompt-can-i-disable-it%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Your code does not capture your prompt, it captures input. Your prompt is already stored in an environment variable named
PS1though.– Jesse_b
3 hours ago
when I run echo "'${PS1}'" in the shell, I get '[e]0;u@h: wa]${debian_chroot:+($debian_chroot)}u@h:w$ '
– conanDrum
3 hours ago
when I run echo "'${PS1}'" in the script, i get ''
– conanDrum
3 hours ago
I noticed that. however I would still like to accomplish this undertaking.
– conanDrum
2 hours ago
Could you say a bit more how the actual value of the prompt ends up in your variable? The prompt is written to the shell's standard error output stream. You would have to actually hop through some hoops to capture it...
– Kusalananda♦
1 hour ago