Enterprise Face question 11:
The shell scripts were developed to compare 2 integer sizes in the same way as script arguments and read reads. Alerts users to compare results in a screen-out manner.
Note: Altogether is the development of 2 scripts. When a script is used to pass a parameter and read in the way it needs to determine whether the variable is a number, and how many parameters to pass.
My script =========================
#read读入方式
#!/bin/Bashread-P"pls input num1:"Num1read-P"pls input num2:"num2[-Z $num 1-a-z $num 2] && { Echo "usage:pls input, num {num1 num2}"Exit1}[ "' echo"$num 1"|sed-r ' s#[^0-9]# #g '"="$num 1"] || { Echo "First arg must be int."Exit2}[ "' echo"$num 2"|sed-r ' s#[^0-9]# #g '"="$num 2"] || { Echo "second arg must be int."Exit3}[$num 1-lt $num 2] && { Echo "$num 1 < $num 2"}[$num 1-GT $num 2] && { Echo "$num 1 > $num 2"}[$num 1-eq $num 2] && { Echo "$num 1 = $num 2"}
#脚本传参方式 #!/bin/bash[$#-ne2]&&{ Echo "usage:num1 num2"Exit1}[ "' echo"$1"|sed-r ' s#[^0-9]# #g '"=" $"]||{ Echo "First arg must be int."Exit2}[ "' echo"$2"|sed-r ' s#[^0-9]# #g '"=" $"]||{ Echo "second arg must be int."Exit2}[ $1-lt $2]&&{ Echo "$1<$2"Exit0}[ $1-eq $2]&&{ Echo "$1=$2"Exit0}[ $1-GT $2]&&{ Echo "$1>$2"Exit0}
Qualified Linux OPS personnel must be 30 shell programming surface questions and explanations-11