I have a basic script to find the max of 2 numbers using a user-defined function; but, I need to convert it to accept 4 numbers, and I am having a hard time. Here is the script.
#!/bin/bash
echo $1 $2 | awk '
{
print max($1, $2)
}
function max(a, b) {
return a > b ? a: b
}'
You would simply execute it by doing: ./scriptname 1 2 (or whatever two numbers you want) and the output would be the max of the two numbers.
I think I can just do the following.
#!/bin/bash
echo $1 $2 $3 $4 | awk '
{
print max($1, $2, $3, $4)
}
function max(a, b, c, d) {
return a < b ? a: b
}'
I am having trouble with line 7, the "return" line. Any suggestions?
Thanks
-CableGuy
max2(a,b)returning the max of inputs, and wantmax4(a,b,c,d)returning max of inputs. Then not thatmax4(a,b,c,d)=max2(max2(a,b),max2(c,d))or equivalentlymax2(max2(max2(a,b),c),d)