Shell计算器
#!/bin/bash
# filename : jisuan.sh
# description : add, subtract, multiply, and divide
print_usage(){
echo -e "USAGE:$0 NUM1 {+|-|*|%} NUM2"
exit 1
}
if [ $# -ne 3 ];then
print_usage
fi
firstnum=$1
secondnum=$3
op=$2
if [ -n "$(echo $firstnum|sed 's/[0-9]//g')" ];then
print_usage
fi
if [ "$op" != "+" ]&&[ "$op!="-"" ]&&[ "$op" != "*" ]&&[ "$op" != "/" ];then
print_usage
fi
if [ -n "$(echo $secondnum|sed 's/[0-9]//g')" ];then
print_usage
fi
echo "${firstnum}${op}${secondnum}=$((${firstnum}${op}${secondnum}))"
另;echo $(($1))
Shell计算器的更多相关文章
- centos7 shell 计算器 bc 命令
2021-08-03 1. 安装 yum -y install bc 2. 简介 bc 命令是任意精度计算器语言,通常在 linux 下当计算器使用 类似基本的计算器, 使用这个计算器可以做基本的数学 ...
- shell(3):文本处理、基本语法和脚本编写
一.awk.变量.运算符.if多分支 awk:shell编辑器的一种文本处理工具/命令,同grep.sed一样均可解释正则.具体运用下面awk文本处理有详细说明. 变量:分为系统变量和临时变量.变量一 ...
- shell命令行混合进制计算器smartbc
需要简单的计算的时候,不想用GUI的计算器,能在shell下直接计算就最好了 查了下,有个东西叫 bc, 具体的使用就不赘述了,可以运行bc,然后进去计算,也可以echo传递过去,大概是像这样 ec ...
- shell 命令 bc linux下的计算器
bc命令 在linux环境下的计算器.
- Shell系列(33) - 多分支if语句简介及计算器例子
多分支if条件语句 if [ 条件判断式1 ] then 当条件判断式1成立时,执行程序1 elif [ 条件判断式2 ] then 当条件判断式2成立时,执行程序2 ...省略更多条件... els ...
- shell写的计算器
#!/bin/bashif [ $# -ne 3 ] then echo "Usage: $0 num1 + num2" fi case $2 in +) echo $1$2$3= ...
- shell应用之简单计算器
1 #!/bin/bash 2 while : 3 do 4 read -p "请输入计算规则:" JS 5 if [ -z $JS ];then 6 exit 7 else 8 ...
- shell if 浮点数比较
转shell中的浮点数比较http://nigelzeng.iteye.com/blog/1604640 博客分类: Bash Shell shell比较浮点数 由于程序需要,我要判断一个浮点数是否 ...
- Classic Shell 4.2.4 中文版已经发布
新版本支持 windows 10 操作系统了.请点击本博客页面左上角的链接下载. 博主的电脑最近也升级到 Windows 10 操作系统,用了没几天就出现打不开“开始”菜单.Edge.计算器等 App ...
随机推荐
- python 读取excel数据插入到另外一个excel
#-*-coding:utf-8-*- import xlrd import xlwt def excel_copy(dir_from, dir_to, sheet_name): '''从一个exce ...
- navicat连接MySQL8.0.11提示2059错误
错误原因:mysql加密规则的改变: mysql加密规则:mysql_native_password mysql8之前的版本 caching_sha2_password mysq ...
- [POI2014]Freight
题目大意: 有两个城镇$A$和$B$,有$n(n\le10^6)$辆车从$A$地出发前往$B$再返回$A$地.两地之间的行驶时间为$s(s\le10^9)$,每辆车从$A$地出发的最早时间是$t_i( ...
- openfire源码修改后如何打包部署到linux服务器上
原文:http://blog.csdn.net/jinzhencs/article/details/50457152 1.linux版本的3.10.3解压部署启动(过程略,参考我的另一篇博文http: ...
- iOS教程:如何使用Core Data – 预加载和引入数据
这是接着上一次<iOS教程:Core Data数据持久性存储基础教程>的后续教程,程序也会使用上一次制作完成的. 再上一个教程中,我们只做了一个数据模型,之后我们使用这个数据模型中的数据创 ...
- Get Started with Subversion using SvnX
A very important part of a development environment is source code control. Subversion is the server- ...
- [置顶]
kubernetes-kubectl命令说明
kubectl kubectl controls the K8S cluster manager. Find more information at https://github.com/K8S/K8 ...
- 使用ajax,结合jquery,php实现图片上传预览功能
大致逻辑:点击页面的file,上传图片到指定的php处理图片的文件,处理完成以后,将图片的连接地址返回,JS控制返回的数据,然后将图片动态的展示出来html代码<label> <im ...
- Chrome的Waterfall
参考: 1.https://developers.google.com/web/tools/chrome-devtools/network-performance/reference#timing 2 ...
- C++完美实现Singleton模式[转]
Singleton模式是常用的设计模式之一,但是要实现一个真正实用的设计模式却也不是件容易的事情.1. 标准的实现class Singleton{public: static Singleton * ...