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. ImageView 设置图片

      android doc中是这样描述的: public void setImageResource (int resId) 这是其中的一个方法,参数resld是这样: ImageView.setIm ...

  2. Spring 实践 -拾遗

    Spring 实践 标签: Java与设计模式 Junit集成 前面多次用到@RunWith与@ContextConfiguration,在测试类添加这两个注解,程序就会自动加载Spring配置并初始 ...

  3. 编译busybox错误

    为了制作一个文件系统,首先要用busybox编译出文件系统所需要的应用程序.在下载了busybox-1.13.0.tar.bz2后,编译出现如下错误: In file included from /o ...

  4. AIX LVM 常用命令记录

    针对物理卷的操作指令 lsdev--列出ODM中的设备 chdev--修改一个AIX设备的属性 mkdev--创建一个AIX设备 chpv--修改物理卷的状态和属性 lspv--查看AIX中物理卷的相 ...

  5. 一:ZooKeeper简介

    一:背景                --->随着互联网技术的高速发展,企业对计算机系统的计算,存储能力要求越来越高,最简单的明证就是出现一些诸如:高并发,海量存储这样的词汇.在这样的背景下, ...

  6. 看看JavaScript中void(0)的含义

    JavaScript中void是一个操作符,该操作符指定要计算一个表达式但是不返回值. void 操作符用法格式如下:1. javascript:void (expression)2. javascr ...

  7. [转] C# 绘制报表,使用Graphics.DrawString 方法

    原文 Graphics.DrawString 方法 在指定位置并且用指定的 Brush 和Font 对象绘制指定的文本字符串. public void DrawString( string s, Fo ...

  8. Nginx工作原理和优化、漏洞

    1.  Nginx的模块与工作原理 第三方模块:HTTP Upstream Request Hash模块.Notice模块和HTTP Access Key模块. 图1-1展示了Nginx模块常规的HT ...

  9. YII 配置文件

    用YIIFramework的库开发 .... Yii::createWebApplication($config); //没有run Yii::import(class1,true),在将class1 ...

  10. Eclipse插件安装的三种方法

    转自:http://www.blogjava.net/tangzurui/archive/2008/06/30/211669.html  整理了一下格式. (前两种安装方式以多国语言包的安装为例) 1 ...