when i test my shell code, i find that something is confused
tasklist.txt contains text:
1
2
3
and my shell code is (shell.sh):
#! /bin/bash
cat tasklist.txt | while read lines
do
echo $lines
cd /media/ice/0A9AD66165F33762/magnet_data/2019/修改
alpha/changeAlpha/runInMyComputer/80K/alpha0.01/50fs/80_1200
mpirun -np 1 ./bin/ASDMPI cff &
done
echo "end..............."
it prints:
1
2
3
it is right!
but when i change the code to:
#! /bin/bash
cat tasklist.txt | while read lines
do
echo $lines
cd /media/ice/0A9AD66165F33762/magnet_data/2019/修改
alpha/changeAlpha/runInMyComputer/80K/alpha0.01/50fs/80_1200
mpirun -np 1 ./bin/ASDMPI cff &
sleep 1
done
echo "end..............."
it just prints:
1
why is the result different when i add the code: sleep 1
?
my os is ubuntu18.04
=====================================================
adding content :
oldIFS=$IFS;
IFS=$'\n';
for line in $(cat tasklist.txt )
do
echo $line
nohup mpirun -np 1 ./bin/ASDMPI cff &
sleep 1
done
kill -9 $(pgrep ASDMPI)
out put:
1
nohup: appending output to 'nohup.out'
2
nohup: appending output to 'nohup.out'
3
nohup: appending output to 'nohup.out'
but
cat tasklist.txt | while read line
do
echo $line
nohup mpirun -np 1 ./bin/ASDMPI cff &
sleep 1
done
kill -9 $(pgrep ASDMPI)
out put:
1
nohup: appending output to 'nohup.out'
my "nohup mpirun -np 1 ./bin/ASDMPI cff & " may be special ,if you change the "nohup mpirun -np 1 ./bin/ASDMPI cff & " to other command ,it will show right. but i don't konw what bug with "nohup mpirun -np 1 ./bin/ASDMPI cff & " .and i will break the while?