0

Does anyone know why after the first iteration I am out of the while loop here ? It used to work like yesterday!! (Same input file containing many lines, no new-lines)

#!/bin/sh
FLAGS_IN=MY_TEXT_FILE_CONTAINING_LOTS_OF_LINE

while read  BENCHMARK DATASET  CF
do
    echo "$BENCHMARK"
    echo "$DATASET"
    echo "$CF"
    N=$((N + 1))    

cd $tmp    
echo "**********************************************************"
            GCC_OPT="-O3"
            OPT_FLAGS=$CF
###### do sth



tmp=$PWD
done <  $FLAGS_IN

exit 0

debugging, I am sure the scripts work till the end of the loop pretty fine.

2
  • 1
    an empty value for the var tmp will the evaluate as a cd cmd without an argument, and send your script to you home dir. You don't include in your code anything like tmp=/tmp/dir so we can't be sure what is happening. Why do you need a cd $tmp after reading each line? Otherwise, if it used to work and it doesn't work today, AND if you really didn't make any changes to the script, or ftp it from MSWindows to Linux, then it must be your data file. Use a text editor with a binary mode to see what is after the first line. Good luck. Commented Feb 24, 2014 at 21:25
  • @shellter, tnx for reply. actually i have used this tmp somewhere in the begining of while cuz inside I am moving around some directories, that's why at the end I would like to go back where I was Commented Feb 24, 2014 at 21:31

1 Answer 1

2

Your #do sth apparently contains a command that reads from standard input, so the next time the read executes, the end of the stream is reached. Pick a file handle you aren't using (3 is probably safe), and use that for your while loop:

while read BENCHMARK DATASET CF <&3
do
    # ...
done 3< $FLAGS_IN
Sign up to request clarification or add additional context in comments.

1 Comment

thanks a lot, it took like an hour of mine, was totally out of idea what was happening, this file handle is working for me now

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.