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 表示 ...
随机推荐
- Linux日志文件(常见)及其功能
日志文件是重要的系统信息文件,其中记录了许多重要的系统事件,包括用户的登录信息.系统的启动信息.系统的安全信息.邮件相关信息.各种服务相关信息等.这些信息有些非常敏感,所以在 Linux 中这些日志文 ...
- join 查询优化
在开发中往往会出现查询多表联查的情况,那么就会用到 join 查询. Join查询种类 为了方便说明,先定义一个统一的表,下面再做例子. CREATE TABLE `t2` ( `id` int(11 ...
- MySQL中 utf8与utf8mb4的区别
MySQL中 utf8与utf8mb4的区别 一.简介 MySQL在5.5.3之后增加了这个utf8mb4的编码,mb4就是most bytes 4的意思,专门用来兼容四字节的unicode.好在 ...
- missing required library sqlite.dll最终解决办法
missing required library sqlite.dll最终解决办法 昨天电脑还是好的,今天早晨打开navicat连接Mysql无缘无故报错"missing required ...
- Edition-Based Redefinition
Oracle在11g引入了Edition-Based Redefinition(EBR),主要是为了解决在更新数据库对象,比如PL/SQL程序,视图等,如果该对象被锁住了,会导致更新必须等待,如果要使 ...
- @functools.lru_cache()
django.views.debug.get_default_exception_reporter_filter @functools.lru_cache()def get_default_excep ...
- Apache HTTP Server 映射URL到文件系统(翻译)
div.example { background-color: rgba(229, 236, 243, 1); color: rgba(0, 0, 0, 1); padding: 0.5em; mar ...
- 框架spring+strutrs+ibatis
Tomcat加载完成 --- Web.xml --- sql-map-config.xml --- 读取xml(*-ibatis-config) --- Jsp的url --- action方法 -- ...
- Language Guide (proto3) | proto3 语言指南(二)标量值类型
标量值类型 标量消息字段可以具有以下类型之一 -- 下表显示了.proto文件中指定的类型,以及自动生成的类中相应的类型: .proto Type 说明 C++ Type Java Type Pyth ...
- MySql(五)SQL优化-优化SQL语句的一般步骤
MySql(五)SQL优化-优化SQL语句的一般步骤 一.优化SQL语句的一般步骤 1.1 通过show status命令了解各种SQL的执行频率 1.2 定位执行效率较低的SQL语句 1.3 通过e ...