$RANDOM
A personal understanding is a variable used to generate a random number, thus writing a script
[email protected] script]# cat random.sh
#!/bin/bash
#
Declare-i max=0
Declare-i min=0
For I in ' seq 1 10 '; Do
Myrandom= $RANDOM
[$I-eq 1] && min= $RANDOM
If [$I-le 9]; Then
Echo-n "$MYRANDOM,"
Else
echo "$MYRANDOM"
Fi
[$MYRANDOM-gt $MAX] && max= $MYRANDOM
[$MYRANDOM-lt $MIN] && min= $MYRANDOM
Done
Echo $MAX, $MIN
[Email protected] script]#
This script is used to compare the number of random numbers generated to a maximum and minimum number and display
Script Execution Results:
[Email protected] script]# bash random.sh
20744,24195,5854,24168,10197,16685,10095,27664,14198,22593
27664, 5854
[Email protected] script]#
Programming is divided into two categories
Process oriented
Control structure
Sequential structure
Select structure
Loop structure
Object oriented
Select structure
If statement: Single branch, dual branch, multi-branch
Now a new choice structure case
Use formatting
Case $ in
value1)
Statement
...
;; (Note that you must add a double semicolon)
value2)
Statement
...
;;
VALUE3)
Statement
...
;;
Esac
Here's a simple script when the user follows a parameter to identify whether it's a number or an uppercase or lowercase letter, or a special character
[email protected] script]# cat recognition.sh
#!/bin/bash
#
Case $ in
[0-9])
echo "a number";;
[[: Upper:]])
echo "Upper";;
[[: Lower:]])
echo "a lower case";;
*)
echo "special character";;
Esac
[Email protected] script]#
Execution Result:
[Email protected] script]#/recognition.sh 2
A number
[Email protected] script]#./recognition.sh E
Upper
[Email protected] script]#./recognition.sh E
A lower case
[[email protected] script]#./recognition.sh #
Special character
[Email protected] script]#
Of course I this only support single-character, later study advanced again practice, here only do a brief introduction!! Oo
Not to be continued
Script Editor $random and Case statements (notes) to be continued