[Linux_Shell learn scripting knowledge to determine whether incoming parameter is an integer]

 

    Determine whether the script is an integer parameter passed several commonly used method

      

 

    Complete Shell scripts are as follows:

      

#! / bin / SH 
############################################ ####################### 
# judge whether incoming parameter is the script method for determining numbers 
# Author: left rock 
# a Date: 2019 - 07 - 26 
Version # 1.0 
############################################### #################### 

## use grep regular 
IF  grep  ' ^ [[: digit for:]] * $ ' <<< " $. 1 " ; the then 
    echo  " $. 1 Number IS. "  
the else 
    echo  ' NO. '  
Fi 

# use redirect the error output to determine 
if [ "$1" -gt 0 ] 2>/dev/null ;then
    echo "$1 is number." 
else
echo 'no.' 
fi

# 使用表达式来判断
expr $1 "+"10 &> /dev/null
if [ $? -eq 0 ];then
        echo "$1 is number" 
else
echo "$1 not number" 
fi

 

Guess you like

Origin www.cnblogs.com/kangxinxin/p/11248040.html