My script reads a list of ".bag" files from a textfile supplied as an argument. and does something with each one. (for clarity, I have omitted most of the "stuff")
while IFS= read -r bag
do
echo Extracting from $bag
# Play the script for saving the images
python2 extract_imgs.py --image_topics "$image_topics" --basepath "extracted_imgs/$bag_name" &
extract_imgs_PID=$!
# play the bag file
rosbag play -r 10 $bag
echo rosbag play returned: $?
echo finished playing $bag
# kill the subscribe node
kill $extract_imgs_PID
done < $1
If I comment out the rosbag play -r 10 $bag line, this script behaves as I expect: It reads each line from $1 and runs an iteration of the loop with that line set as $bag.
But with the 'rosbag play -r 10 $bag' line, it works correctly for the first line, but then exits the loop and finishes. Why? the return status of rosbag play is 0. How can I get this script to run the rosbag play command and then continue looping over the lines of the input file?
rosbagis reading from stdin, stealing lines fromread. See Why redirect stdin inside a while read loop in bash? and Shell script while read line loop stops after the first line