I have an executable, say it's called a.out. It takes two lines of input after a prompt --
> ./a.out
> give me input-1: 0 0 10
> give me input-2: 10 10 5
> this is the output: 20 20 20
I can store the inputs in a file (input.txt) and redirect it to a.out, the file looks like this --
0 0 10
10 10 5
and I can call a.out like --
> ./a.out < input.txt
> give me input-1: 0 0 10 give me input-2: 10 10 5
> this is the output: 20 20 20
Now I want to store multiple inputs in that file and redirect into a.out. The file will look like this with 2 inputs --
0 0 10
10 10 5
0 0 20
10 10 6
and I am writing a bash script like --
exec 5< input.txt
while read line1 <&5; do
read line2 <&5;
./a.out < `printf "$line1\n$line2"` ;
done
It does not work, how do I do that?
printf '%s\n' "$line1" "$line2"; that way you don't introduce bugs if anything inline1orline2reads as a format string.