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 表示 ...
随机推荐
- JavaScript中函数的调用!
JavaScript中函数的调用! 1 普通函数 // 1 普通函数 function fn() { console.log(123); } // 函数名 + 一个小括号! 或者 函数名.call() ...
- Index-Only Scans and Covering Indexes
小结: 1.覆盖索引 回表 2. All indexes in PostgreSQL are secondary indexes, meaning that each index is stored ...
- WPF和MVVM的结合使用方法,不可错过
Model:存储数据模型(类) 也在此业务逻辑,主要负责类文件的存储. ViewModel:连接View和Model,借助Command来负责界面的跳转和调用Model中方法来操作Model的数据. ...
- Language Guide (proto3) | proto3 语言指南(六)嵌套类型
Nested Types - 嵌套类型 您可以在其他消息类型中定义和使用消息类型,如以下示例所示--这里的Result消息是在SearchResponse消息中定义的: message SearchR ...
- docker通过dockerfile构建JDK最小镜像,Docker导出导入镜像
docker通过dockerfile构建JDK最小镜像,Docker导出导入镜像 一.docker通过dockerfile构建JDK最小镜像 1.1 下载JRE 1.2 解压JRE,删除相关不需要文件 ...
- c++ stl list使用总结(转)
转自:http://blog.csdn.net/nupt123456789/article/details/8120397 #include <iostream> #include < ...
- 提供读取excel 的方法
/** * 对外提供读取excel 的方法 * */ public static List<List<Object>> readExcel(String path) throw ...
- cassandra权威指南读书笔记--cassandra查询语言
cassandra使用一个特殊主键(复合键)表示宽行,宽行也叫分区.复合键由一个分区键和一组可选的集群列组成.分区键用于确定存储行的节点,分区键也可以包含多个列.集群键用于控制数据如何排序以及在分区中 ...
- Linux 防火墙相关操作
目录 1.查看防火墙状态 2.部署防火墙 3.常用操作 4.其他操作 1.查看防火墙状态 systemctl status firewalld 绿字部分 Active:active(running) ...
- OLAP、OLTP的介绍和比较(转载)
OLTP与OLAP的介绍 数据处理大致可以分成两大类:联机事务处理OLTP(on-line transaction processing).联机分析处理OLAP(On-Line Analytical ...