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. 当Vue可视化工具创建不了项目时的解决办法!

    当Vue可视化工具创建不了项目时的解决办法! 当你尝试用可视化工具创建一个Vue的项目的时候,报错, 出现什么indexOf什么什么的错误! 我的解决办法是把可视化工具删除掉,重新下载! 如果你是 n ...

  2. 深入理解 MySQL 索引底层原理

    https://mp.weixin.qq.com/s/qHJiTjpvDikFcdl9SRL97Q

  3. TypeScript基本类型

    类型注解 作用:相当于强类型语言中的类型声明 语法:(变量/函数):type 数据类型 新建src/datatype.ts,里面定义各种类型的数据 原始类型: let bool: boolean = ...

  4. Group by 优化

    一个标准的 Group by 语句包含排序.分组.聚合函数,比如 select a,count(*) from t group by a ;  这个语句默认使用 a 进行排序.如果 a 列没有索引,那 ...

  5. Java 从Character和char的区别来学习自动拆箱装箱

    本文结构 1.Character和char 的区别: 2.自动拆箱装箱 1.Character和char 的区别: Character是类,char基本数据类型. 在java中有三个类负责对字符的操作 ...

  6. python基础(数据类型,while,if)

    python基础初识. 1,运行python代码. 在d盘下创建一个t1.py文件内容是: print('hello world') 打开windows命令行输入cmd,确定后 写入代码python ...

  7. DP中的树上边/点覆盖问题

    目录 树上边覆盖问题 例:luoguP2016 战略游戏 简述题意: Solution: Code 树上点覆盖问题 简述题意 Solution Code: 树上边覆盖问题 例:luoguP2016 战 ...

  8. SpringMVC听课笔记(二:SpringMVC的 HelloWorld)

    1.如何建Maven web项目,请看http://how2j.cn/k/maven/maven-eclipse-web-project/1334.html 2.Maven项目,pom文件中的jar包 ...

  9. Tomcat优化,JNDI,连接池,数据源

    什么是JNDI? JNDI的简单应用 什么是连接池技术? 连接池 性能 连接池技术与传统数据库连接的比较 连接池技术工作原理 为什么使用连接池? 传统数据库连接方式的不足 企业级开发需要稳健和高效的数 ...

  10. Tomcat Context容器和Wrapper容器

    前言 Wrapper容器 前言 Context容器是一个Web项目的代表,主要管理Servlet实例,在Tomcat中Servlet实例是以Wrapper出现的,现在问题是如何才能通过Context容 ...