Shell randomly generates 10 numbers to find the maximum value

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.