Bash's ArithmeticExpression
【Bash's ArithmeticExpression】
let command:
let a=17+23
echo "a = $a" # Prints a = 40
let a=17 + 23 # WRONG
let a="17 + 23" # Right
let a=28/6
echo "a = $a" # Prints a = 4
In addition to the let command, one may use the (( )) syntax to enforce an arithmetic context. If there is a $ (dollar sign) before the parentheses, then a substitution is performed (more on this below). White space is allowed inside (( )) with much greater leniency than with normal assignments, and variables inside (( )) don't require $(because string literals aren't allowed):
(( )) without the leading $ is a Bash-only feature. $(( )) substitution is allowed in the POSIX shell. As one would expect, the result of the arithmetic expression inside the$(( )) is substituted into the original command. Here are some examples of the use of the arithmetic substitution syntax:
use declare command to set the type of a variant
declare -i b # Declare b as an integer
参考:http://bash.cumulonim.biz/ArithmeticExpression.html
Bash's ArithmeticExpression的更多相关文章
- bash's [ command & [[ keyword
[bash's [ command & [[ keyword] [ (test) command: bash中的条件测试語句, [ condition ], 并不是一个語句, 而是一个命令, ...
- 怎样用 Bash 编程:逻辑操作符和 shell 扩展
学习逻辑操作符和 shell 扩展,本文是三篇 Bash 编程系列的第二篇. Bash 是一种强大的编程语言,完美契合命令行和 shell 脚本.本系列(三篇文章,基于我的 三集 Linux 自学课程 ...
- scp报错 -bash: scp: command not found
环境:RHEL6.5 使用scp命令报错: [root@oradb23 media]# scp /etc/hosts oradb24:/etc/ -bash: scp: command not fou ...
- bash字符串操作
参考 http://www.cnblogs.com/chengmo/archive/2010/10/02/1841355.html 问题:bash怎么提取字符串的最后一位?例如python中strin ...
- grep 查找bash脚本中的注释代码
出于安全性的考虑,不建议在bash脚本中注释掉不使用的代码.也就是说如果某段代码不使用了,那么应该删除掉,而不是简单地注释掉.假如你突然意识到这一点,而以前并没有遵从这个原则,现在需要找出脚本中的注释 ...
- Bash 脚本编程语言中的美学与哲学
我承认,我再一次地当了标题党.但是不可否认,这一定是一篇精华随笔.在这一篇中,我将探讨 Bash 脚本语言中的美学与哲学. 这不是一篇 Bash 脚本编程的教程,但是却能让人更加深入地了解 Bash ...
- cmder git bash 使用
cmder 是一款 windows 下的命令集合软件,它可以集合各种系统下的命令,并且操作非常快速方便. 安装有两个版本,一个是简化版(4.27M),一个是完全版(75.7M),它们的唯一区别:完全版 ...
- 安装完成后在命令行运行bash时报错0x80070057
在命令运行bash 提示如下: 解决方法,不启用旧版本控制台: 右键命令提示栏 打开属性,把勾选去掉如下图红色边框标识: 然后重启,就可以使用,也包括可以打开Bash on Unbuntu on Wi ...
- Bash简明教程--变量
1. 前言 Bash是一门流行在*nix系统下的脚本语言.作为一门脚本语言,变量是一门语言的基本要素,在这篇教程中,我们将学习Bash中的变量是怎么表示的,以及变量相关的一些语法规则. 2. Bash ...
随机推荐
- KEYUSE
typedef struct keyuse_t { TABLE *table; Item *val; /**< or value if no field */ table_map used_ta ...
- Windows Live Writer配置测试
文字可以了 不知道代码怎么发布
- LA 3027 Corporative Network
这题感觉和 POJ 1988 Cube Stacking 很像,在路径压缩的同时递归出来的时候跟新distant数组 我发现我一直WA的原因是,命令结束是以字母o结束的,而不是数字0!! //#def ...
- hdu 1429 胜利大逃亡(续) (bfs+状态压缩)
又开始刷题了 题意:略过. 分析:主要是确定状态量,除了坐标(x,y)之外,还有一个key状态,就好比手上拿着一串钥匙.状态可以用位运算来表示:key&(x,y)表示判断有没有这扇门的钥匙,k ...
- 基于Html5的爱情主题网站–表白神器(第二版)
第二版在第一版的基础上增加了一个动态3D的白云效果背景,鼠标悬浮在页面上云朵会向屏幕Z轴方向运动,在第一人称视角看来向着云朵方向前进的,由此形成一个伪3D效果.有点绕,直接看demo就能理解了.3D白 ...
- Java正则表达式之语法规则
正则表达式是一种强大而灵活的文本处理工具,使用正则表达式能够以编程的方式,构造复杂的文本模式,并对输入的字符串进行搜索.一旦找到了匹配这些模式的部分,就能够随心所欲地它们进行处理.正则表达式提供了一种 ...
- Sqoop的使用(Mysql To HBase)
最近需要将mysql的数据整合到HBase中,原本使用MapReduce,自己制作job将mysql的数据导入, 查阅资料过程中,发现了开源工具sqoop(关系性数据库与HDFS,HBASE,HIVE ...
- zoj 2105 Lifting the Stone
题意 裸的计算几何 求多边形重心: #include<iostream> #include<stdio.h> #include<cstring> #inclu ...
- ssl创建自签名的https通信
ssl协议:ssl在tcp之上,http之下.兼容底层协议.所以推广起来很容易. create a self-signed server certificate -- for test purpose ...
- iOS 5.0 后UIViewController新增:willMoveToParentViewController和didMoveToParentViewCon
在iOS 5.0以前,我们在一个UIViewController中这样组织相关的UIView 在以前,一个UIViewController的View可能有很多小的子view.这些子view很多时候 ...