Shell Scripting 1

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Shell Scripting 1相关的知识,希望对你有一定的参考价值。

通过expr判断变量是否为整数

[[email protected] scripts]# cat judge.sh
#!/bin/bash
##############################################################
# File Name: judge.sh
# Version: V1.0
# Author: Rain Jin
# Blog Site: http://www.cnblogs.com/rainjin/
# Created Time : 2017-10-27 21:19:42
# Environment: CentOS 7.2 Kernal 3.10.0
##############################################################
#judging if the arguments you have entered are integers;
if [ $# -ne 2 ]
then
echo "USAGE:$0 INT1 INT2"
exit 1
fi

a=$1
b=$2
expr $a + 1 &>/dev/null
RETVAL_A=$?
expr $b + 1 &>/dev/null
RETVAL_B=$?
if [ $RETVAL_A -ne 0 -o $RETVAL_B -ne 0 ]
then
echo "one of your input is not int."
exit 1
fi

echo "a-b = $(( $a - $b ))"
echo "a+b = $(( $a + $b ))"
echo "a*b = $(( $a * $b ))"
echo "a/b = $(( $a / $b ))"
echo "a**b = $(( $a ** $b ))"
echo "a%b = $(( $a % $b ))"































以上是关于Shell Scripting 1的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Shell Scripting 中检查目录是不是为空? [复制]

Shell编程速查手册

如何使用perl遍历一个目录下的所有文件

VBS使用Scripting.Dictionary字典对象

Excel:Scripting.Dictionary

访问 VBA:Scripting.Dictionary - 转储到表?