Copache
Copache

Reputation: 23

Bash: Sending data file into C program line by line

I have a question regarding sending data from a file line by line to a C program that will then convert the data's values from Fahrenheit to Kelvin. How do I read in the program line by line and then grab the output line by line back into my script?

Upvotes: 0

Views: 56

Answers (1)

pjh
pjh

Reputation: 8064

It's not really clear what is required here because the interface to the converter program is not specified. Assuming that the program is called f2k, that it reads Fahrenheit values one-per-line from standard input and writes the converted values one-per-line to standard output, and that the file fahrenheits.txt contains a list of Fahrenheit values, one-per-line, this will put a newline-separated list of the Kelvin values into the kelvins variable:

kelvins=$(f2k <fahrenheits.txt)

Upvotes: 1

Related Questions