I tried to write a program that can read input from a file, and got stuck.my program is  prog:#!/bin/bashnum=$(($1 + $2))echo $nummy input test.in:11I used./prog < test1.inbut got error message./prog: line 2: + : syntax error: operand expected (error token is + )What's wrong?Thanks!
Redirect input from a file to a program
linux;bash
What you have written is not a program that reads input from a file, but a program that takes its input in the form of positional parameters (aka command-line arguments). The redirection operator < sends your file data to the program's standard input stream (aka stdin) - which your program ignores.At its simplest, to read one line per value from standard input, you could change your program to#!/bin/bashread aread bnum=$((a+b))echo $numNow when you redirect stdin from your test file, the result should be$ ./newprog < test1.in2Alternatively you could have used the xargs utility to read your file data and pass its contents to your program as arguments$ xargs -a test1.in ./prog2