While loops not looping through all valuesprocessing command output line by line, without mixing standard...

Why don't electron-positron collisions release infinite energy?

The magic money tree problem

Do airline pilots ever risk not hearing communication directed to them specifically, from traffic controllers?

Is there a familial term for apples and pears?

How to add power-LED to my small amplifier?

How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?

Infinite past with a beginning?

Underlining section titles

When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?

Why has Russell's definition of numbers using equivalence classes been finally abandoned? ( If it has actually been abandoned).

How to type dʒ symbol (IPA) on Mac?

Pronouncing Dictionary.com's W.O.D "vade mecum" in English

"You are your self first supporter", a more proper way to say it

What is the command to reset a PC without deleting any files

Should I join office cleaning event for free?

Japan - Plan around max visa duration

Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)

Is it possible to do 50 km distance without any previous training?

How is it possible to have an ability score that is less than 3?

Why is an old chain unsafe?

Is it possible to make sharp wind that can cut stuff from afar?

What is the offset in a seaplane's hull?

How can the DM most effectively choose 1 out of an odd number of players to be targeted by an attack or effect?

How to report a triplet of septets in NMR tabulation?



While loops not looping through all values


processing command output line by line, without mixing standard inputIn a Bash Script how does the continue command work with embedded loops?Cron only occasionally sends e-mail on output and errorsLooping through unix datesWhy isn't my .bashrc file being read from .profileparallel processing reading from a file in a loopWhere is pdfwriter.py located?Read through a fileWhat can be reason for getting “execute permission denied” in cronjob in UNIX?Looping through all sub directories in a folder?unable to run bash script from bash script






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







1















I have created a few pieces of code - in python and C – that have to be run multiple times, each run with a new set of input values. To do so, I have created a Unix shell script which should run the various programs for the number of different inputs:



#!/bin/sh
_file="${1:-/dev/null}"

while IFS=' ' read -r f1 f2 f3 f4
do
cd folder1
cd folder2
echo "$f1 $f2 $f3 $f4 " > inputs.txt
mpiexec -n 4 a_C_code
cd ..
cd ..
python3 python_code_1.py
python python_code_2.py
python python_code_3.py
python python_code_4.py
echo "$f1" #So I know how many times the loops has been performed

done < "$_file"


The file that is being read into the script has the following form:



1 2 3 4
5 6 7 8
...



However, when I execute the program, it only loops through the first set of inputs (in this example, 1 2 3 4) and finishes without running the programs for the various other sets of inputs.










share|improve this question









New contributor




JasKa071 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1





    Perhaps one of the commands inside the loop is consuming standard input? see for examle processing command output line by line, without mixing standard input

    – steeldriver
    20 hours ago


















1















I have created a few pieces of code - in python and C – that have to be run multiple times, each run with a new set of input values. To do so, I have created a Unix shell script which should run the various programs for the number of different inputs:



#!/bin/sh
_file="${1:-/dev/null}"

while IFS=' ' read -r f1 f2 f3 f4
do
cd folder1
cd folder2
echo "$f1 $f2 $f3 $f4 " > inputs.txt
mpiexec -n 4 a_C_code
cd ..
cd ..
python3 python_code_1.py
python python_code_2.py
python python_code_3.py
python python_code_4.py
echo "$f1" #So I know how many times the loops has been performed

done < "$_file"


The file that is being read into the script has the following form:



1 2 3 4
5 6 7 8
...



However, when I execute the program, it only loops through the first set of inputs (in this example, 1 2 3 4) and finishes without running the programs for the various other sets of inputs.










share|improve this question









New contributor




JasKa071 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1





    Perhaps one of the commands inside the loop is consuming standard input? see for examle processing command output line by line, without mixing standard input

    – steeldriver
    20 hours ago














1












1








1








I have created a few pieces of code - in python and C – that have to be run multiple times, each run with a new set of input values. To do so, I have created a Unix shell script which should run the various programs for the number of different inputs:



#!/bin/sh
_file="${1:-/dev/null}"

while IFS=' ' read -r f1 f2 f3 f4
do
cd folder1
cd folder2
echo "$f1 $f2 $f3 $f4 " > inputs.txt
mpiexec -n 4 a_C_code
cd ..
cd ..
python3 python_code_1.py
python python_code_2.py
python python_code_3.py
python python_code_4.py
echo "$f1" #So I know how many times the loops has been performed

done < "$_file"


The file that is being read into the script has the following form:



1 2 3 4
5 6 7 8
...



However, when I execute the program, it only loops through the first set of inputs (in this example, 1 2 3 4) and finishes without running the programs for the various other sets of inputs.










share|improve this question









New contributor




JasKa071 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I have created a few pieces of code - in python and C – that have to be run multiple times, each run with a new set of input values. To do so, I have created a Unix shell script which should run the various programs for the number of different inputs:



#!/bin/sh
_file="${1:-/dev/null}"

while IFS=' ' read -r f1 f2 f3 f4
do
cd folder1
cd folder2
echo "$f1 $f2 $f3 $f4 " > inputs.txt
mpiexec -n 4 a_C_code
cd ..
cd ..
python3 python_code_1.py
python python_code_2.py
python python_code_3.py
python python_code_4.py
echo "$f1" #So I know how many times the loops has been performed

done < "$_file"


The file that is being read into the script has the following form:



1 2 3 4
5 6 7 8
...



However, when I execute the program, it only loops through the first set of inputs (in this example, 1 2 3 4) and finishes without running the programs for the various other sets of inputs.







shell-script shell






share|improve this question









New contributor




JasKa071 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




JasKa071 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 15 hours ago









Rui F Ribeiro

42k1483142




42k1483142






New contributor




JasKa071 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 20 hours ago









JasKa071JasKa071

82




82




New contributor




JasKa071 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





JasKa071 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






JasKa071 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1





    Perhaps one of the commands inside the loop is consuming standard input? see for examle processing command output line by line, without mixing standard input

    – steeldriver
    20 hours ago














  • 1





    Perhaps one of the commands inside the loop is consuming standard input? see for examle processing command output line by line, without mixing standard input

    – steeldriver
    20 hours ago








1




1





Perhaps one of the commands inside the loop is consuming standard input? see for examle processing command output line by line, without mixing standard input

– steeldriver
20 hours ago





Perhaps one of the commands inside the loop is consuming standard input? see for examle processing command output line by line, without mixing standard input

– steeldriver
20 hours ago










1 Answer
1






active

oldest

votes


















1














The shell code looks OK, and a simplified text version works as expected:



seq 12 | paste - - - - | 
while IFS=' ' read -r f1 f2 f3 f4 ; do
echo "$f1 $f2 $f3 $f4 "
done


Output:



1   2   3   4    
5 6 7 8
9 10 11 12


Therefore steeldriver's comment is probably correct, and either the mpiexec or one of the python programs are consuming the remaining lines of input so that echo never gets to the second line of input.



As an example, consider the above code with one more hungry set of commands added:



seq 12 | paste - - - - | 
while IFS=' ' read -r f1 f2 f3 f4 ; do
echo "$f1 $f2 $f3 $f4 "
(read x; read x; read x;)
done


Output (note the missing lines):



1   2   3   4   





share|improve this answer


























  • Thank you so much for your answer. It turns out that mpiexec is consuming the remainder of the inputs.

    – JasKa071
    19 hours ago












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
});


}
});






JasKa071 is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f510974%2fwhile-loops-not-looping-through-all-values%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









1














The shell code looks OK, and a simplified text version works as expected:



seq 12 | paste - - - - | 
while IFS=' ' read -r f1 f2 f3 f4 ; do
echo "$f1 $f2 $f3 $f4 "
done


Output:



1   2   3   4    
5 6 7 8
9 10 11 12


Therefore steeldriver's comment is probably correct, and either the mpiexec or one of the python programs are consuming the remaining lines of input so that echo never gets to the second line of input.



As an example, consider the above code with one more hungry set of commands added:



seq 12 | paste - - - - | 
while IFS=' ' read -r f1 f2 f3 f4 ; do
echo "$f1 $f2 $f3 $f4 "
(read x; read x; read x;)
done


Output (note the missing lines):



1   2   3   4   





share|improve this answer


























  • Thank you so much for your answer. It turns out that mpiexec is consuming the remainder of the inputs.

    – JasKa071
    19 hours ago
















1














The shell code looks OK, and a simplified text version works as expected:



seq 12 | paste - - - - | 
while IFS=' ' read -r f1 f2 f3 f4 ; do
echo "$f1 $f2 $f3 $f4 "
done


Output:



1   2   3   4    
5 6 7 8
9 10 11 12


Therefore steeldriver's comment is probably correct, and either the mpiexec or one of the python programs are consuming the remaining lines of input so that echo never gets to the second line of input.



As an example, consider the above code with one more hungry set of commands added:



seq 12 | paste - - - - | 
while IFS=' ' read -r f1 f2 f3 f4 ; do
echo "$f1 $f2 $f3 $f4 "
(read x; read x; read x;)
done


Output (note the missing lines):



1   2   3   4   





share|improve this answer


























  • Thank you so much for your answer. It turns out that mpiexec is consuming the remainder of the inputs.

    – JasKa071
    19 hours ago














1












1








1







The shell code looks OK, and a simplified text version works as expected:



seq 12 | paste - - - - | 
while IFS=' ' read -r f1 f2 f3 f4 ; do
echo "$f1 $f2 $f3 $f4 "
done


Output:



1   2   3   4    
5 6 7 8
9 10 11 12


Therefore steeldriver's comment is probably correct, and either the mpiexec or one of the python programs are consuming the remaining lines of input so that echo never gets to the second line of input.



As an example, consider the above code with one more hungry set of commands added:



seq 12 | paste - - - - | 
while IFS=' ' read -r f1 f2 f3 f4 ; do
echo "$f1 $f2 $f3 $f4 "
(read x; read x; read x;)
done


Output (note the missing lines):



1   2   3   4   





share|improve this answer















The shell code looks OK, and a simplified text version works as expected:



seq 12 | paste - - - - | 
while IFS=' ' read -r f1 f2 f3 f4 ; do
echo "$f1 $f2 $f3 $f4 "
done


Output:



1   2   3   4    
5 6 7 8
9 10 11 12


Therefore steeldriver's comment is probably correct, and either the mpiexec or one of the python programs are consuming the remaining lines of input so that echo never gets to the second line of input.



As an example, consider the above code with one more hungry set of commands added:



seq 12 | paste - - - - | 
while IFS=' ' read -r f1 f2 f3 f4 ; do
echo "$f1 $f2 $f3 $f4 "
(read x; read x; read x;)
done


Output (note the missing lines):



1   2   3   4   






share|improve this answer














share|improve this answer



share|improve this answer








edited 18 hours ago

























answered 19 hours ago









agcagc

4,79211138




4,79211138













  • Thank you so much for your answer. It turns out that mpiexec is consuming the remainder of the inputs.

    – JasKa071
    19 hours ago



















  • Thank you so much for your answer. It turns out that mpiexec is consuming the remainder of the inputs.

    – JasKa071
    19 hours ago

















Thank you so much for your answer. It turns out that mpiexec is consuming the remainder of the inputs.

– JasKa071
19 hours ago





Thank you so much for your answer. It turns out that mpiexec is consuming the remainder of the inputs.

– JasKa071
19 hours ago










JasKa071 is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















JasKa071 is a new contributor. Be nice, and check out our Code of Conduct.













JasKa071 is a new contributor. Be nice, and check out our Code of Conduct.












JasKa071 is a new contributor. Be nice, and check out our Code of Conduct.
















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%2f510974%2fwhile-loops-not-looping-through-all-values%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







Popular posts from this blog

Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...