shell运算
发布时间:2020-12-16 01:38:14 所属栏目:安全 来源:网络整理
导读:shell运算 整数运算:expr,$(()),$[] expr 使用expr进行运算,如果遇到特殊字符,则需要转义,如* [[email?protected] ~]# num1=2[[email?protected] ~]# num2=5[[email?protected] ~]# expr $num1 + $num27[[email?protected] ~]# expr $num1 - $num2-3[[
shell运算整数运算:expr,$(()),$[] expr使用expr进行运算,如果遇到特殊字符,则需要转义,如* [[email?protected] ~]# num1=2 [[email?protected] ~]# num2=5 [[email?protected] ~]# expr $num1 + $num2 7 [[email?protected] ~]# expr $num1 - $num2 -3 [[email?protected] ~]# expr $num1 * $num2 #需要转移 10 [[email?protected] ~]# expr $num2 / $num1 2 [[email?protected] ~]# expr $num2 % $num1 1 [[email?protected] ~]# $(()) $[]? 不需要转义,都可以直接使用 计算字符串长度:[[email?protected] opt]# a="abcd" [[email?protected] opt]# echo $(($(echo $a|wc -c)-1)) # 比较麻烦 4 [[email?protected] opt]# echo ${#a} # 高级用法 4 [[email?protected] opt]# EOF多行输出:# cat << EOF > test.sh > #!/bin/bash > #you Shell script writes here. > EOF 结果: 引用# cat test.sh #!/bin/bash #you Shell script writes here. [[email?protected] opt]# cat <<EOF > hello world > this is my girlfriend! > what's wrong? > Are you OK? > EOF hello world this is my girlfriend! what's wrong? Are you OK? [[email?protected] opt]# if语句中的文件比较条件成立,则执行&&后面的内容 # && 条件不成立,则执行 || 后面的 # || 数值比较(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |