1

I am new to bash and writing a script to read variables that is stored on each line of a text file (there are thousands of these variables). So I tried to write a script that would read the lines and automatically output the solution to the screen and save into another text file.

./reader.sh > solution.text

The problem I encounter is currently I have only 1 variable store in the Sheetone.txt for testing purpose which should take about 2 seconds to output everything but it is stuck in the while loop as well as is not outputting the solution.

#!/bin/bash
file=Sheetone.txt
while IFS= read -r line
do
        echo sh /usr/local/test/bin/test -ID $line -I 
done
2
  • 3
    Your while read does not have any input, you may want to say do ... done < file so that it is fed by the content of file. Commented Jun 22, 2015 at 14:43
  • Use done < "$file" Commented Jun 22, 2015 at 14:44

1 Answer 1

2

As indicated in the comments, you need to provide "something" to your while loop. The while construct is written in a way that will execute with a condition; if a file is given, it will proceed until the read exhausts.

#!/bin/bash
file=Sheetone.txt
while IFS= read -r line
do
    echo sh /usr/local/test/bin/test -ID $line -I 
done < "$file"
# -----^^^^^^^ a file!

Otherwise, it was like cycling without wheels...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.