进行加减乘除的shell运算脚本
2011-02-21 09:50
465 查看
#!/bin/bash
####################################################################
# Author: netcat #
# Lable: calc.sh #
# Information: Simple calculator #
# Create Date: 2011-02-21 #
# Version: v 1.0 #
####################################################################
echo "example: 3 + 5"
read -p "enter: " a b c
echo $a|grep [a-zA-Z]>/dev/null
if [ $? -ne 0 ];then
echo $c|grep [a-zA-Z]>/dev/null
if [ $? -ne 0 ];then
if [ $b == "+" ]
then
let x=$a+$c
echo "$a + $c = $x"
fi
if [ $b == "-" ]
then
let x=$a-$c
echo "$a - $c = $x"
fi
if [ $b == "x" ]
then
let x=$a*$c
echo "$a x $c = $x"
fi
if [ $b == "/" ]
then
let x=$a/$c
echo "$a / $c = $x"
fi
else
echo "$c is not data"
fi
else
echo "$a is not data"
fi
运行效果:
####################################################################
# Author: netcat #
# Lable: calc.sh #
# Information: Simple calculator #
# Create Date: 2011-02-21 #
# Version: v 1.0 #
####################################################################
echo "example: 3 + 5"
read -p "enter: " a b c
echo $a|grep [a-zA-Z]>/dev/null
if [ $? -ne 0 ];then
echo $c|grep [a-zA-Z]>/dev/null
if [ $? -ne 0 ];then
if [ $b == "+" ]
then
let x=$a+$c
echo "$a + $c = $x"
fi
if [ $b == "-" ]
then
let x=$a-$c
echo "$a - $c = $x"
fi
if [ $b == "x" ]
then
let x=$a*$c
echo "$a x $c = $x"
fi
if [ $b == "/" ]
then
let x=$a/$c
echo "$a / $c = $x"
fi
else
echo "$c is not data"
fi
else
echo "$a is not data"
fi
运行效果:
相关文章推荐
- Shell脚本攻略03-使用shell进行数学运算
- 17_Shell语言―――如何在shell 脚本中进行算术运算
- Linux 下用shell脚本对SVN 修改的文件进行备份
- shell脚本算术运算
- 【shell脚本】命令代换 ` `, $( ) ,整数运算$(( )),变量代换${ },eval命令
- shell下进行简单的运算
- 利用Shell脚本进行文件内容去重
- shell中用bc进行浮点运算
- shell脚本中的数值运算
- 使用shell脚本对Linux系统和进程资源进行监控
- 使用shell脚本进行服务器系统监控——系统负载监控(3)
- bash特性之逻辑运算和shell脚本的编写
- Shell脚本编程中常用的数学运算实例
- shell 脚本对变量进行字符串截取
- 使用Shell脚本对Linux系统和进程资源进行监控
- Shell脚本基础10-基本的数学运算
- 编写shell脚本对mysql数据库进行定时备份
- 如何进行shell脚本正确性测试
- 在Shell脚本中使用Trap捕获相关信号进行hook
- shell 脚本对 Linux 系统和进程资源进行监控