Analysis: Randomly generate 10 numbers? Generate a random number, here with the random function, I define the generated 10 numbers as an array of arrays, the initial value of the definition max is array[0] use for loop to compare with each element's value, if there is greater than array[0], if ARRAY[3] Larger than array[0], then assign the value of Array[3] to Max, traverse the comparison of each array element, and finally output Max's value!
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/87/54/wKiom1fdLerj1U7nAABmwAfrYpc545.png "title=" 99.PNG "alt=" Wkiom1fdlerj1u7naabmwafrypc545.png "/> Look at the implementation of the situation ....
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/87/51/wKioL1fdLlCCmRhqAAAeoiztPrA628.png "title=" 99.PNG "alt=" Wkiol1fdllccmrhqaaaeoiztpra628.png "/> Text
#!/bin/bash
#Author: Wangergui email:[email protected] date:2016-09-17
#Release 1.0
#Function find maxnum from array
Path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:~/bin
Export PATH
Declare-a Array
For J in {0..9};d o
Array[${j}]=${random}
Echo-n "${array[${j}]}"
Sleep 1
Max=${array[0]}
For I in ${!array[@]};d o
if [[${max}-le ${array[${i}]}]];then
Max=${array[${i}]}
Fi
Done
Done
Echo
ECHO-E "The array element max is:\e[40;31;1m $MAX \e[0m"
This article from the "Linux-related technology" blog, declined to reprint!
Shell randomly generates 10 numbers to find the maximum value