bash variables plus operator All In One

Errors

missing pass params

#!/usr/bin/env bash

# echo  emoji ^-v-^
# echo " emoji ^-v-^" # = 两边不可以有空格
# arg1 = $1
# OK, no space
arg1=$1
arg2=$2
sum=$(($arg1 + $arg2)) echo $arg1
echo $arg2
# -e 换行
echo -e "\n"
echo $sum
#!/bin/bash

# OK, no space
arg1=$1
arg2=$2
sum=$(($arg1 + $arg2)) echo $arg1
echo $arg2
# -e 换行
echo -e "\n"
echo $sum

Solutions

just need pass args OR 参数可以为空

#!/usr/bin/env bash

# echo  emoji ^-v-^
# echo " emoji ^-v-^" # = 两边不可以有空格
# arg1 = $1
# OK, no space
arg1=$1
arg2=$2
# , 参数可以为空
sum=$((arg1 + arg2))
# OR
# , 参数不可以为空
# sum=$(($arg1 + $arg2)) echo $arg1
echo $arg2
# -e 换行
echo -e "\n"
echo $sum # DEMO
# ./sum.sh 1 2
#!/bin/bash

# OK, no space
arg1=$1
arg2=$2
# , 参数可以为空
sum=$((arg1 + arg2))
# OR
# , 参数不可以为空
# sum=$(($arg1 + $arg2)) echo $arg1
echo $arg2
# -e 换行
echo -e "\n"
echo $sum # DEMO
# ./add.sh 1 2

bash add operator

#!/bin/bash

#!/usr/bin/env bash

arg1=$1
arg2=$2 #
num=$(($arg1 + $arg2)) #
str=$((arg1 + arg2)) echo "num: \$arg1 + \$arg2 = $num"
# -e 换行
echo -e "\n"
echo "str: arg1 + arg2 = $str" # DEMO
# ./num.sh 1 2 # num: $arg1 + $arg2 = 3 # str: arg1 + arg2 = 3
#!/usr/bin/env bash

arg1=$1
arg2=$2 #
num=$(($arg1 + $arg2)) #
str=$((arg1 + arg2)) echo "num: \$arg1 + \$arg2 = $num"
# -e 换行
echo -e "\n"
echo "str: arg1 + arg2 = $str" # DEMO
# ./str.sh 1 2 # num: $arg1 + $arg2 = 3 # str: arg1 + arg2 = 3

https://github.com/xgqfrms/linux/blob/master/zsh/num.sh

https://github.com/xgqfrms/linux/blob/master/zsh/str.sh

refs

https://www.imooc.com/notepad/2582fb

https://www.imooc.com/u/1066707/notepad/336

https://www.howtogeek.com/442332/how-to-work-with-variables-in-bash/



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


bash variables plus operator All In One的更多相关文章

  1. Bash Scripting Learn Notes

    References: [1] http://www.tldp.org/LDP/Bash-Beginners-Guide/html/ 1. Executing programs from a scri ...

  2. Bash For Loop Examples for Your Linux Shell Scripting--ref

    There are two types of bash for loops available. One using the “in” keyword with list of values, ano ...

  3. Bash String Manipulation Examples – Length, Substring, Find and Replace--reference

    In bash shell, when you use a dollar sign followed by a variable name, shell expands the variable wi ...

  4. bash中(),{},(()),[],[[]]的区别

    前言:在bash中遇到各种括号,同时在进行字符数值比较判定时,总是不断出现问题,于是通过参考<advanced bash-scripting guide>,同时在centos 6.7版本上 ...

  5. 完全总结bash中的条件判断test [ [[ 使用

    在bash脚本编程中,我们经常做一些条件判断, 我们主要用到了三种,test,单中括号,双中括号 经常有看到不同的写法,如: [ $? –eq ] [[ $myvar == “mysql” ]] te ...

  6. linux bash算术运算

    +, -, *(乘), /(除), **(乘方), %(取模) let var=算术运算符表达式 var=$[算术运算符表达式] var=$((算术运算符表达式)) var=$(expr $ARG1 ...

  7. bash5.0参考手册

    Bash Reference Manual a.summary-letter { text-decoration: none } blockquote.indentedblock { margin-r ...

  8. Shell 编程基础之 [ 与 [[ 的异同

    一.简介 [ 与 test 等价,是 bash 的内部命令,GNU/linux 系统的 coreutils 软件包通常带 /usr/bin/test 和 /usr/bin/[ 命令.如果我们不用绝对路 ...

  9. HANA SQLScript

    数据类型 日期时间类型 DATE(日期) DATE 数据类型由年.月.日信息组成,表示一个日期值. DATA 类型的默认格式为‘YYYY-MM-DD’. YYYY 表示年, MM 表示月而 DD 表示 ...

随机推荐

  1. MySQL全面瓦解21(番外):一次深夜优化亿级数据分页的奇妙经历

    背景 1月22号晚上10点半,下班后愉快的坐在在回家的地铁上,心里想着周末的生活怎么安排. 突然电话响了起来,一看是我们的一个开发同学,顿时紧张了起来,本周的版本已经发布过了,这时候打电话一般来说是线 ...

  2. 浅析Redis与IO多路复用器原理

    为什么Redis使用多路复用I/O Redis 是跑在单线程中的,所有的操作都是按照顺序线性执行的,但是由于读写操作等待用户输入或输出都是阻塞的,所以 I/O 操作在一般情况下往往不能直接返回,这会导 ...

  3. 如何实现new,call,apply,bind的底层原理。

    new做了什么? new是用来实例化对象的,当new了一个对象后 1.创建一个新对象 2.将构造函数的作用域赋值给新对象(this指向新对象) 3.执行构造函数里面的代码(为这个新对象添加属性) 4. ...

  4. Hive语法小释

    阅读本文你可以获取: 1.数据库的查询 2.hive表的基本操作(建表三种常用方式.删除表.修改表.加载数据.内外表转换.添加分区.复制数据) 3.SQL到HiveQL的的一些不同点 1.   基本操 ...

  5. (转载)微软数据挖掘算法:Microsoft 决策树分析算法(1)

    微软数据挖掘算法:Microsoft 目录篇 介绍: Microsoft 决策树算法是分类和回归算法,用于对离散和连续属性进行预测性建模. 对于离散属性,该算法根据数据集中输入列之间的关系进行预测. ...

  6. Folly解读(零) Fbstring—— 一个完美替代std::string的库

    string 常见的三种实现方式 eager copy COW SSO Fbstring 介绍 Storage strategies Implementation highlights Benchma ...

  7. GCD之队列的实现和使用

    一.什么是GCD? 以下是摘自苹果的官方说明. Grand Central Dispatch(GCD)是异步执行任务的技术之一.一般将应用程序中记述的线程管理用的代码在系统级中实现.开发者只需要定义想 ...

  8. SDNUOJ1016矩形合并

    传送门 题意: 给出n个矩形,把重合的矩形归成一个图形,问合并以后剩下几个图形 思路: 我开始想用dfs,但是发现不太行. 后来知道才是并查集 Orz 用一个结构体数组存矩形的左下角和右上角的坐标,再 ...

  9. POJ - 3693 Maximum repetition substring(重复次数最多的连续重复子串)

    传送门:POJ - 3693   题意:给你一个字符串,求重复次数最多的连续重复子串,如果有一样的,取字典序小的字符串. 题解: 比较容易理解的部分就是枚举长度为L,然后看长度为L的字符串最多连续出现 ...

  10. A. Little Pony and Expected Maximum

    Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she ...