Qualified Linux OPS personnel must be 30 shell programming surface questions and explanations-11

Source: Internet
Author: User

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

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.