bash算数运算&命令引用

简介:

1.bash脚本编程之算数运算

+ - * / %

declare -i num3=5 //直接声明为整数

declare -i num4=6

echo “$num3+$num4" //结果为5+6

(1) let c="$num1+$num2"

(2) echo "$[$num1+$num2]" //$中括号和小括号,let,expr

(3) echo "$(($sum1+$sum2))"

(4) expr $num2 + $num4

sum=$(expr $num1 + $num2) //命令引用模式

echo "`expr $num1 + $num2`"

echo `expr $num1 + $num2`

expr支持很多运算

|,&,>,>=,=,!=,等等

注意:乘法符号在有些场景中,需要使用转义符;

练习:

写一个脚本,完成如下功能;

添加三个用户,

求此三个用户的UID之和

#!/bin/bash

a="$(id -u wolf)"

b="$(id -u root)"

c="$(id -u test)"

sum="$(expr $a + $b + $c)"

echo $sum

bash算数

let,expr,$[],$(())


2.命令引用

` ` //反引号

$(COMMAND) //引用












本文转自MT_IT51CTO博客,原文链接:http://blog.51cto.com/hmtk520/1942860,如需转载请自行联系原作者

相关文章
|
4月前
|
Linux Shell Windows
4:Bash shell命令-步入Linux的现代方法
4:Bash shell命令-步入Linux的现代方法
53 0
|
6月前
|
关系型数据库 MySQL Shell
【Linux命令】-bash: mysql: command not found
【Linux命令】-bash: mysql: command not found
56 0
|
4月前
|
Shell
-bash: lsb_release: 未找到命令
-bash: lsb_release: 未找到命令
|
5月前
|
Shell
bash 反弹命令的浅分析
bash 反弹命令的浅分析
27 0
|
8月前
|
Shell Linux
10.1.5 查询指令是否为 Bash shell 的内置命令: type
10.1.5 查询指令是否为 Bash shell 的内置命令: type
60 0
|
8月前
|
Shell 测试技术 Python
如何在Bash Shell脚本中使用`exec`命令?
如何在Bash Shell脚本中使用`exec`命令?
129 0
|
10月前
|
Java Linux Shell
Centos7 bash:jps:未找到命令
Centos7 bash:jps:未找到命令
194 0
|
10月前
|
Shell
【Shell编程】Shell中Bash变量-数值运算、运算符变量、测试和内容替换
【Shell编程】Shell中Bash变量-数值运算、运算符变量、测试和内容替换
56 0
|
11月前
|
Shell
bash 命令概要
bash 命令概要
|
11月前
|
Shell Linux
Linux pip命令报错 -bash: pip: command not found
Linux pip命令报错 -bash: pip: command not found
252 0