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 表示 ...
随机推荐
- 封装JSONP 函数,方便请求发送
封装JSONP 函数,方便请求发送 封装jsonp的代码和封装Ajax的代码非常的相似!可以参照食用偶! <button id="btn">点击我发送请求!</b ...
- eNSP启动设备AR1失败记一次解决步骤
eNSP稳定版本下载: 微信搜索公众号"疯刘小三" 关注后回复ensp即可获得下载链接地址 eNSP V100R002C00B510 Setup.exe 最近在用eNSp的时候 ...
- shell批量解压源码包
有时候部署环境有很多安装包,如果一个一个地解压缩实在太麻烦了,可以用shell批量进行解压缩.命令如下: [root@localhost ~]# vi tar.sh #! /bin/bash #标称是 ...
- Jmeter接口自动化测试系列之函数使用及扩展
介绍一下Jmeter自带函数的使用和 函数扩展,来满足测试工作中的各种需求! Jmeter自带函数 点击函数帮助助手图标,弹出函数助手框,可以选择各种各样的函数 举例: _Random 获取随机数,可 ...
- LinuxCentos7下安装Mysql8.x以及密码修改
LinuxCentos7下安装Mysql以及密码修改 引言: 之前都是用Docker或者yum自动安装,这次主要是下载压缩包解压安装,中间也有些小波折,记录如下,以供参考: 1.删除旧的MySQL 检 ...
- 在QML 中用javascritpt 将中文转换拼音,可以在音标
项目需要, 今天整理了一下.在QML调用javascrit将中文汉字转换成拼音. 感觉执行效率低.下面是主要代码. 具体代码请参考QMLPinyin 代码 ```import "./piny ...
- 简单makefile
https://www.cnblogs.com/prettyshuang/p/5552328.html#_label0
- macro-name replacement-text 宏 调试开关可以使用一个宏来实现 do { } while(0)
C++ 预处理器_w3cschool https://www.w3cschool.cn/cpp/cpp-preprocessor.html C++ 预处理器 预处理器是一些指令,指示编译器在实际编译之 ...
- Communicating sequential processes CSP 通信顺序进程 CSP writing to a file by name (process, Erlang) vs. writing to a file descriptor (channel, Go)
the-way-to-go_ZH_CN/01.2.md at master · Unknwon/the-way-to-go_ZH_CN https://github.com/Unknwon/the-w ...
- 四. Ribbon负载均衡服务调用
1. 概述 1.1 Ribbon是什么 SpringCloud Ribbon是基于Netflix Ribbon实现的一套客户端,是负载均衡的工具. Ribbon是Netflix发布的开源项目,主要功能 ...