If we have an AWK script (average.sh) like this and would like to use it to process a lot of inputfiles:
awk -F\" 'BEGIN{print}
last != $4""$8 && last{
print line,exp(C/D)
C=D=0}
{ # This block process each line of infile
C += log($(NF-1)+0)
D++
$(NF-1)=""
line=$0
last=$4""$8}
END{ # This block triggers after the complete file read
# to print the last average that cannot be trigger during
# the previous block
print line,exp(C/D)}' ${var2:=infile}
Now if we do
export var2="infile4" | sh average.sh
The "average.sh" still process "infile" instead of "infile4".
Following the best answers in Override a variable in a Bash script from the command line , we try
var2=infile4 ./geometric_average_real
This give an error of "var2=infile: Command not found."
Our final goal is to write loops
for (X=1; X<=3; X++)
do
sh average.sh infile${X}
done
so this loop shall process
sh average.sh infile1
sh average.sh infile2
sh average.sh infile3