Saying the above script gives you no result is misleading. With a three line input file, it produces three lines of output (each output line being an empty line). You haven't said what you are trying to do with this script (or function). As written, it appears that the intent is to print the smallest value read so far for each line read. I.e., the output from the 1st line read will be the first line read, the output from the 2nd line read will be the smaller of the 1st two values read, and the output from the 3rd line read will be the smallest of the 1st three values read.
But, your function doesn't look for the smallest value in the number of lines read; instead it looks for the smaller value in the 3rd and 4th values (in an array that never has more than three values included when reading a three line input file). And, since the 4th value in that array is the default empty string assumed by any unassigned variable (which is treated as a zero value when compared to an integer), the result of each call to your function was an empty string.
Rewriting fun.awk to only use elements of the array that have actually been assigned variables (and reformatting to make the structure more obvious):
And if the data sample suggested in post #2 is stored in a file named file , the command:
awk -f fun.awk file
produces the output:
1
1
1
1
1
1
1
1
1
0
-1
-1
-1
-1
-1
-1
If the goal of the script is to just print the smallest value read (and a function is required rather than keeping track of the smallest value seen while reading the data), that would be written as:
{
small()
}
function small() {
smal=a[NR]=$0
for(i = 1; i < NR; i++) {
if(a < smal)
smal=a
}
return smal
}
END {
print small()
}