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的更多相关文章

  1. bash's [ command & [[ keyword

    [bash's [ command & [[ keyword] [ (test) command: bash中的条件测试語句, [ condition ], 并不是一个語句, 而是一个命令, ...

  2. 怎样用 Bash 编程:逻辑操作符和 shell 扩展

    学习逻辑操作符和 shell 扩展,本文是三篇 Bash 编程系列的第二篇. Bash 是一种强大的编程语言,完美契合命令行和 shell 脚本.本系列(三篇文章,基于我的 三集 Linux 自学课程 ...

  3. scp报错 -bash: scp: command not found

    环境:RHEL6.5 使用scp命令报错: [root@oradb23 media]# scp /etc/hosts oradb24:/etc/ -bash: scp: command not fou ...

  4. bash字符串操作

    参考 http://www.cnblogs.com/chengmo/archive/2010/10/02/1841355.html 问题:bash怎么提取字符串的最后一位?例如python中strin ...

  5. grep 查找bash脚本中的注释代码

    出于安全性的考虑,不建议在bash脚本中注释掉不使用的代码.也就是说如果某段代码不使用了,那么应该删除掉,而不是简单地注释掉.假如你突然意识到这一点,而以前并没有遵从这个原则,现在需要找出脚本中的注释 ...

  6. Bash 脚本编程语言中的美学与哲学

    我承认,我再一次地当了标题党.但是不可否认,这一定是一篇精华随笔.在这一篇中,我将探讨 Bash 脚本语言中的美学与哲学. 这不是一篇 Bash 脚本编程的教程,但是却能让人更加深入地了解 Bash ...

  7. cmder git bash 使用

    cmder 是一款 windows 下的命令集合软件,它可以集合各种系统下的命令,并且操作非常快速方便. 安装有两个版本,一个是简化版(4.27M),一个是完全版(75.7M),它们的唯一区别:完全版 ...

  8. 安装完成后在命令行运行bash时报错0x80070057

    在命令运行bash 提示如下: 解决方法,不启用旧版本控制台: 右键命令提示栏 打开属性,把勾选去掉如下图红色边框标识: 然后重启,就可以使用,也包括可以打开Bash on Unbuntu on Wi ...

  9. Bash简明教程--变量

    1. 前言 Bash是一门流行在*nix系统下的脚本语言.作为一门脚本语言,变量是一门语言的基本要素,在这篇教程中,我们将学习Bash中的变量是怎么表示的,以及变量相关的一些语法规则. 2. Bash ...

随机推荐

  1. aptana studio 3支持jquery

    首先要说的一点是,如果你不使用PortableGit,就不要安装,否则New From Template中会缺失大部分模板.至于还有什么缺陷,暂时没测出来,本人也是刚玩aptana studio 3哈 ...

  2. Bootstrap_组件

    一.Glyphicons 字体图标 1.所有可用的图标查看:http://v3.bootcss.com/components/ 2.获取字体图标:我们已经在 环境安装 章节下载了 Bootstrap ...

  3. 关于NSString的retainCount的各种结果原因

    转载:http://blog.csdn.net/onlyou930/article/details/6932529 http://www.cnblogs.com/celestial/archive/2 ...

  4. simplefactory简单工厂模式

    简单工厂模式概述    又叫静态工厂方法模式,它定义一个具体的工厂类负责一些类的实例 优点    客户端不需要在负责对象的创建,从而明确了各个类的职责 缺点:    这个静态工厂类负责所有对象的创建, ...

  5. I.MX6 Linux、Jni ioctl 差异

    /*********************************************************************** * I.MX6 Linux.Jni ioctl 差异 ...

  6. Android用自己的app替换Launcher

    /*********************************************************************** * Android用自己的app替换Launcher ...

  7. == Rickard Oberg & TheServerSide

    看了Hani Suleiman和Rickard Oberg ,发现其实每个所谓的权威都应该有被质疑的绝对,可能往往权威会令人觉得理所应当

  8. list() and tuple()

    >>> l = list('sdfsdf') >>> l ['s', 'd', 'f', 's', 'd', 'f'] >>> t = tuple ...

  9. Hadoop Hive基础sql语法

     目录 Hive 是基于Hadoop 构建的一套数据仓库分析系统,它提供了丰富的SQL查询方式来分析存储在Hadoop 分布式文件系统中的数据,可以将结构 化的数据文件映射为一张数据库表,并提供完整的 ...

  10. Android 实现切换主题皮肤功能(类似于众多app中的 夜间模式,主题包等)

    首先来个最简单的一键切换主题功能,就做个白天和晚上的主题好了. 先看我们的styles文件: <resources> <!-- Base application theme. --& ...