output of while loop piped to tee and variable missingUse bash's read builtin without a while loopBash :...
Is killing off one of my queer characters homophobic?
Pre-1968 YA science fiction novel: robot with black-and-white vision, later the robot could see in color
Back to the nineties!
Why does the trade federation become so alarmed upon learning the ambassadors are Jedi Knights?
How can an advanced civilization forget how to manufacture its technology?
Does Google Maps take into account hills/inclines for route times?
TikZ Can I draw an arrow by specifying the initial point, direction, and length?
Why is the total number of hard disk sectors shown in fdisk not the same as theoretical calculation?
Find values of x so that the matrix is invertible
How do I write a romance that doesn't look obvious
How to repair a laptop's screen hinges?
How to check the quality of an audio sample?
In which ways do anagamis still experience ignorance?
Why would guns not work in the dungeon?
Measuring mystery distances
What are some symbols representing peasants/oppressed persons fighting back?
The monorail explodes before I can get on it
How does one stock fund's charge of 1% more in operating expenses than another fund lower expected returns by 10%?
What is this welding tool I found in my attic?
When is pointing out a person's hypocrisy not considered to be a logical fallacy?
What to put after taking off rear stabilisers from child bicyle?
Would letting a multiclass character rebuild their character to be single-classed be game-breaking?
QGIS Linestring rendering curves between vertex
nginx serves wrong domain site. It doenst shows default site if no configuration applies
output of while loop piped to tee and variable missing
Use bash's read builtin without a while loopBash : rewriting a file which is read in same lineBroken pipe error when reading stopsredirecting output of a command as if it was file inputUnbuffered socat command to connect serial ports in remote machines and log the dataIs the command in a process substitution invoked in a subshell?Get PID and return code from 1 line bash callRestoring tty correctly with sttyHow Do I Unbuffer The Output Passed From an Interactive Command Into a Pipeline Ending With `tee`?How to get bash completion settings to be inherited by child shells?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
It seems that I have faced a famous problem that "pipes spawn subshells" since it has been asked several times, but in my case it is a bit different so I couldn't use their solutions for my problem. I'm not piping anything into the read command, rather I'm piping the output of the read command to the "tee" to write to an output file:
pevdelete(){
...
pevdeletebool=false
while read -r line
do
if [[ ! $line =~ "export $1=" ]]
then
echo "$line"
else
pevdeletebool=true # probably this gets run in a subshell
envtodelete=$1
fi
done <~/.pev | sudo tee -a pevtemp > /dev/null
# this condition never evaluates to true:
if [[ $pevdeletebool = true ]]; then echo "unset $envtodelete" | tee pevtemp2; source pevtemp2; fi
...
}
The problem is, the condition if [[$pevdeletebool = true ]]; then...
never runs.
(JIC you need to know, the reason I'm writing unset $envtodelete
into a file(pevtemp2) is I want to unset an environment variable from my script and doing it directly won't work. So instead, I have to "source" another script file(pevtemp2) containing that unset command in order to make it work).
pipe environment-variables subshell
add a comment |
It seems that I have faced a famous problem that "pipes spawn subshells" since it has been asked several times, but in my case it is a bit different so I couldn't use their solutions for my problem. I'm not piping anything into the read command, rather I'm piping the output of the read command to the "tee" to write to an output file:
pevdelete(){
...
pevdeletebool=false
while read -r line
do
if [[ ! $line =~ "export $1=" ]]
then
echo "$line"
else
pevdeletebool=true # probably this gets run in a subshell
envtodelete=$1
fi
done <~/.pev | sudo tee -a pevtemp > /dev/null
# this condition never evaluates to true:
if [[ $pevdeletebool = true ]]; then echo "unset $envtodelete" | tee pevtemp2; source pevtemp2; fi
...
}
The problem is, the condition if [[$pevdeletebool = true ]]; then...
never runs.
(JIC you need to know, the reason I'm writing unset $envtodelete
into a file(pevtemp2) is I want to unset an environment variable from my script and doing it directly won't work. So instead, I have to "source" another script file(pevtemp2) containing that unset command in order to make it work).
pipe environment-variables subshell
What solutions couldn't you use? Process substitution is commonly suggested, and it should work fine.
– muru
18 secs ago
add a comment |
It seems that I have faced a famous problem that "pipes spawn subshells" since it has been asked several times, but in my case it is a bit different so I couldn't use their solutions for my problem. I'm not piping anything into the read command, rather I'm piping the output of the read command to the "tee" to write to an output file:
pevdelete(){
...
pevdeletebool=false
while read -r line
do
if [[ ! $line =~ "export $1=" ]]
then
echo "$line"
else
pevdeletebool=true # probably this gets run in a subshell
envtodelete=$1
fi
done <~/.pev | sudo tee -a pevtemp > /dev/null
# this condition never evaluates to true:
if [[ $pevdeletebool = true ]]; then echo "unset $envtodelete" | tee pevtemp2; source pevtemp2; fi
...
}
The problem is, the condition if [[$pevdeletebool = true ]]; then...
never runs.
(JIC you need to know, the reason I'm writing unset $envtodelete
into a file(pevtemp2) is I want to unset an environment variable from my script and doing it directly won't work. So instead, I have to "source" another script file(pevtemp2) containing that unset command in order to make it work).
pipe environment-variables subshell
It seems that I have faced a famous problem that "pipes spawn subshells" since it has been asked several times, but in my case it is a bit different so I couldn't use their solutions for my problem. I'm not piping anything into the read command, rather I'm piping the output of the read command to the "tee" to write to an output file:
pevdelete(){
...
pevdeletebool=false
while read -r line
do
if [[ ! $line =~ "export $1=" ]]
then
echo "$line"
else
pevdeletebool=true # probably this gets run in a subshell
envtodelete=$1
fi
done <~/.pev | sudo tee -a pevtemp > /dev/null
# this condition never evaluates to true:
if [[ $pevdeletebool = true ]]; then echo "unset $envtodelete" | tee pevtemp2; source pevtemp2; fi
...
}
The problem is, the condition if [[$pevdeletebool = true ]]; then...
never runs.
(JIC you need to know, the reason I'm writing unset $envtodelete
into a file(pevtemp2) is I want to unset an environment variable from my script and doing it directly won't work. So instead, I have to "source" another script file(pevtemp2) containing that unset command in order to make it work).
pipe environment-variables subshell
pipe environment-variables subshell
asked 5 mins ago
aderchoxaderchox
157 bronze badges
157 bronze badges
What solutions couldn't you use? Process substitution is commonly suggested, and it should work fine.
– muru
18 secs ago
add a comment |
What solutions couldn't you use? Process substitution is commonly suggested, and it should work fine.
– muru
18 secs ago
What solutions couldn't you use? Process substitution is commonly suggested, and it should work fine.
– muru
18 secs ago
What solutions couldn't you use? Process substitution is commonly suggested, and it should work fine.
– muru
18 secs ago
add a comment |
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
});
}
});
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%2f530043%2foutput-of-while-loop-piped-to-tee-and-variable-missing%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
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%2f530043%2foutput-of-while-loop-piped-to-tee-and-variable-missing%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
What solutions couldn't you use? Process substitution is commonly suggested, and it should work fine.
– muru
18 secs ago