bash variables plus operator All In One
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的更多相关文章
- Bash Scripting Learn Notes
		References: [1] http://www.tldp.org/LDP/Bash-Beginners-Guide/html/ 1. Executing programs from a scri ... 
- 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 ... 
- 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 ... 
- bash中(),{},(()),[],[[]]的区别
		前言:在bash中遇到各种括号,同时在进行字符数值比较判定时,总是不断出现问题,于是通过参考<advanced bash-scripting guide>,同时在centos 6.7版本上 ... 
- 完全总结bash中的条件判断test [ [[ 使用
		在bash脚本编程中,我们经常做一些条件判断, 我们主要用到了三种,test,单中括号,双中括号 经常有看到不同的写法,如: [ $? –eq ] [[ $myvar == “mysql” ]] te ... 
- linux bash算术运算
		+, -, *(乘), /(除), **(乘方), %(取模) let var=算术运算符表达式 var=$[算术运算符表达式] var=$((算术运算符表达式)) var=$(expr $ARG1 ... 
- bash5.0参考手册
		Bash Reference Manual a.summary-letter { text-decoration: none } blockquote.indentedblock { margin-r ... 
- Shell 编程基础之 [ 与 [[ 的异同
		一.简介 [ 与 test 等价,是 bash 的内部命令,GNU/linux 系统的 coreutils 软件包通常带 /usr/bin/test 和 /usr/bin/[ 命令.如果我们不用绝对路 ... 
- HANA SQLScript
		数据类型 日期时间类型 DATE(日期) DATE 数据类型由年.月.日信息组成,表示一个日期值. DATA 类型的默认格式为‘YYYY-MM-DD’. YYYY 表示年, MM 表示月而 DD 表示 ... 
随机推荐
- Mybatis【15】-- Mybatis一对一多表关联查询
			注:代码已托管在GitHub上,地址是:https://github.com/Damaer/Mybatis-Learning ,项目是mybatis-11-one2one,需要自取,需要配置maven ... 
- 简单的DbContext工厂类(EFCore)
			前言 根据appsettings.json的中配置的数据库类型,使用工厂模式创建DbContext 代码实现 appsettings.json中的配置项 //使用的数据库类型 "Server ... 
- 基于Python的接口自动化-unittest测试框架和ddt数据驱动
			引言 在编写接口自动化用例时,我们一般针对一个接口建立一个.py文件,一条接口测试用例封装为一个函数(方法),但是在批量执行的过程中,如果其中一条出错,后面的用例就无法执行,还有在运行大量的接口测试用 ... 
- python元组 列表 (取值、替换、插入、添加、删除)
			1.元组 列表 字典 元组( 元组是不可变的) hello = (1,2,3,4,5) type(hello) 
- EMA algorithm: https://blog.csdn.net/m0_38106113/article/details/81542863
			EMA algorithm: https://blog.csdn.net/m0_38106113/article/details/81542863 
- Enabling Session Persistence 粘性会话
			NGINX Docs | HTTP Load Balancing https://docs.nginx.com/nginx/admin-guide/load-balancer/http-load-ba ... 
- malloc函数   链表 运行时才知道内存 动态内存
			https://baike.baidu.com/item/malloc函数 malloc的全称是memory allocation,中文叫动态内存分配,用于申请一块连续的指定大小的内存块区域以void ... 
- Linux下编译安装源码包软件  configure ,make, make install, make test/check, make clean 假目标
			http://www.360doc7.net/wxarticlenew/541275971.html 一.程序的组成部分 Linux下程序大都是由以下几部分组成: 二进制文件:也就是可以运行的程序文件 ... 
- proc/net/tcp中各项内容的含义
- SparkStreaming直连方式读取kafka数据,使用MySQL保存偏移量
			SparkStreaming直连方式读取kafka数据,使用MySQL保存偏移量 1. ScalikeJDBC 2.配置文件 3.导入依赖的jar包 4.源码测试 通过MySQL保存kafka的偏移量 ... 
