哈哈哈哈哈哈
这篇文章不错!
这篇文章不错!
作者对主题的挖掘深入骨髓,展现了非凡的洞察力和理解力。
情感真挚自然,字里行间传递出强烈的感染力。
作者的情感表达细腻入微,让人在阅读中找到了心灵的慰藉。
内容的丰富性和深度让人仿佛置身于知识的海洋,受益匪浅。
# 图片回复
你的文章让我感受到了正能量,非常棒! https://www.4006400989.com/qyvideo/93624.html
你的文章充满了智慧,让人敬佩。 https://www.yonboz.com/video/12554.html
你的文章让我感受到了正能量,非常棒! https://www.4006400989.com/qyvideo/82001.html
你的文章充满了智慧,让人敬佩。 https://www.yonboz.com/video/83913.html
你的文章让我感受到了正能量,非常棒! https://www.4006400989.com/qyvideo/82001.html
你的文章充满了智慧,让人敬佩。 https://www.yonboz.com/video/83913.html
首页
网站统计
关于本站
在线留言
友链申请
高清壁纸
论坛
开往
虫洞
推荐
Linux命令
资源网
Search
1
Typecho Cuteen主题美化
5,129 阅读
2
京东呆瓜搭建青龙面板+xdd-plus机器人+nvjdc配置
4,597 阅读
3
好久不见之网站底部样式
4,237 阅读
4
傻妞机器人最新版安装教程
4,108 阅读
5
Joe 主题 6.xx 底部增强,显示标签及二维码分享
3,114 阅读
Linux
Shell
Mysql
Typecho
网络
其他
Redis
登录
Search
标签搜索
Linux
Typecho
美化
Nginx
Shell
综合架构
Mysql
Joe
源码
Web
数据备份
命令
Ansible
k8s
定时任务
视频
网易云
白嫖
网络
Rsync
小黑
累计撰写
155
篇文章
累计收到
921
条评论
博主
4月14日
在线
首页
栏目
Linux
Shell
Mysql
Typecho
网络
其他
Redis
页面
网站统计
关于本站
在线留言
友链申请
高清壁纸
推荐
Linux命令
资源网
开往
搜索到
2
篇与
算数运算符
的结果
2021-04-04
Shell 脚本的条件测试与比较
{mtitle title="条件测试常用语法"/}Shell脚本条件测试语法说明test利用test命令进行条件测试[]通过[]进行条件测试[[]]通过[[]]进行条件测试(())通过(())进行条件测试test语法test -f file && echo true || echo false #存在输出true,不存在输出false[]语法[ -f /tmp/123.txt ] && echo 1 || echo 0 #存在输出1,不存在输出0[[]]语法[[ -f /tmp/123.txt ]] &&echo 1 || echo 0 #存在输出1,不存在输出0文件测试表达式{mtitle title="常用的文件测试符"/}文件测试操作符说明-d 文件文件存在且为目录为真,及测试表达式成立-f 文件文件存在且为普通文件为真,及测试表达式成立-e 文件文件存在即为真,则表达式成立,不区别文件和目录-r 文件文件存在且可读为真,及测试表达式成立-w 文件文件存在且可写为真,及测试表达式成立-x 文件文件存在且可执行为真,及测试表达式成立-s 文件文件存在且文件大小不为0为真,及测试表达式成立-L 文件文件存在且为链接文件为真,及测试表达式成立f1 -nt f2文件f1比文件f2新则为真,即表达式成立,根据文件的修改时间来计算f1 -ot f2文件f1比文件f2旧则为真,即表达式成立,根据文件的修改时间来计算字符串测试表达式{mtitle title="字符串测试符"/}字符串测试符说明-n "字符串"若字符串不为“0”,则为真,即表达式成立-z "字符串"若字符串为“0”,则为真,即表达式成立"串1" = "串2"若字符串1等于字符串2,则为真,即表达式成立"串1" != "串2"若字符串1不等于字符串2,则为真,即表达式成立整数二次元比较符在[]以及test中使用的比较符在(())和[[]]中使用的比较符说明-eq==或者=相等-ne!=不相等-gt>大于-ge>=大于等于-lt<小于-le<=小于等于root@cs:/server/scripts# a1=98;a2=64 root@cs:/server/scripts# [ "$a1" -eq "$a2" ] && echo 1 || echo 00 root@cs:/server/scripts# [ "$a1" -ne "$a2" ] && echo 1 || echo 01 root@cs:/server/scripts# [ "$a1" -gt "$a2" ] && echo 1 || echo 01 root@cs:/server/scripts# [ "$a1" -lt "$a2" ] && echo 1 || echo 00逻辑操作符{mtitle title="逻辑操作符"/}在[]和test中使用的操作符在[[]]和(())中使用的操作符说明-a&&and,与,两端为真,则结果为真-o双竖线or,或,两端一个为真,则结果为真!!not,非,两端相反,则结果为真使用-a和&&时当左边为真,右边为假时,结果为假。当左边为假,右边为真时,结果为假。当左边为真,右边为真时,结果为真。当左边为假,右边为假时,结果为假。root@cs:/server/scripts# [ 5 -eq 6 -a 7 -ne 5 ] && echo 1 || echo 0 #5等于7?假 7不等于5? 真 结果为假 输出0 0 root@cs:/server/scripts# [ 5 -lt 6 -a 7 -ne 5 ] && echo 1 || echo 0 #5<7?真 7不等于5? 真 结果为真 输出1 1使用-o 或 双竖线时当左边为真,右边为假时,结果为真。当左边为假,右边为真时,结果为真。当左边为真,右边为真时,结果为真。当左边为假,右边为假时,结果为假。root@cs:/server/scripts# [ 5 -lt 6 -o 7 -ne 5 ] && echo 1 || echo 0 1 root@cs:/server/scripts# [ 5 -eq 6 -o 7 -ne 5 ] && echo 1 || echo 0 1 root@cs:/server/scripts# [ 5 -gt 6 -o 7 -lt 5 ] && echo 1 || echo 0 0root@cs:/server/scripts# f1=/etc/rc.local;f2=/etc/services root@cs:/server/scripts# echo -ne "$f1 $f2\n" /etc/rc.local /etc/services root@cs:/server/scripts# [ -f "$f1" -a -f "$f2" ] && echo 1 || echo 0 1 root@cs:/server/scripts# [ -f "$f1" -a -f "$f222" ] && echo 1 || echo 0 0 root@cs:/server/scripts# [ -f "$f1" -o -f "$f222" ] && echo 1 || echo 0 1 root@cs:/server/scripts# [ -f "$f111" -o -f "$f222" ] && echo 1 || echo 0 0 root@cs:/server/scripts# [ -f "$f1" ] && [ -f "$f2" ] && echo 1 || echo 0 1 root@cs:/server/scripts# a="test";b="echo" root@cs:/server/scripts# echo -eq "$a $b\n" -eq test echo\n root@cs:/server/scripts# echo -ne "$a $b\n" test echo root@cs:/server/scripts# [[ ! -n "$a" && "$a" = "$b" ]] && echo 0 || echo 1 1 root@cs:/server/scripts# [[ -z "$a" && "$a" != "$b" ]] && echo 0 || echo 1 1 root@cs:/server/scripts# [[ -z "$a" || "$a" != "$b" ]] && echo 0 || echo 1 0 root@cs:/server/scripts# [[ -z "$a" -o "$a" != "$b" ]] && echo 0 || echo 1 -bash: syntax error in conditional expression -bash: syntax error near `-o'root@cs:/server/scripts# m=21;n=38 root@cs:/server/scripts# [ $m -gt 20 -a $n -lt 30 ] && echo 1 || echo 0 0 root@cs:/server/scripts# [ $m -gt 20 ] && [ $n -lt 30 ] && echo 1 || echo 0 0 root@cs:/server/scripts# [ $m -gt 20 ] || [ $n -lt 30 ] && echo 1 || echo 0 1逻辑操作符输入或通过命令行输入一个数字,如果传入的数字等于1,就打印1,输入2,就打印2,输入其他数字就退出程序root@cs:/server/scripts# cat ljczf.sh #!/bin/bash read -p "please input num:" num [ "$num" = "1" ] && { echo 1 exit 0 } [ "$num" = "2" ] && { echo 2 exit 0 } [ "$num" != "1" -a "$num" != "2" ] && { echo error exit 1 }传参方式 root@cs:/server/scripts# cat ljczf1.sh #!/bin/bash echo "plase input num" num=$1 [ "$num" = "1" ] && { echo 1 exit 0 } [ "$num" = "2" ] && { echo 2 exit 0 } [ "$num" != "1" -a "$num" != "2" ] && { echo error exit 1 }比较两个整数的大小root@cs:/server/scripts# cat int.sh #!/bin/bash read -p "pls input two num:" num1 num2 [ -z "$num1" -a -z "$num2" ] && { echo error exit 1 } expr $num1 + 1 &>/dev/null RETVAL_n1=$? expr $num2 + 1 &>/dev/null RETVAL_n2=$? [ $RETVAL_n1 -eq 0 -a $RETVAL_n2 -eq 0 ] || { echo "pls input two num again" exit 2 } [ $num1 -lt $num2 ] && { echo "$num1 < $num2" exit 0 } [ $num1 -eq $num2 ] && { echo "$num1 = $num2" exit 0 } [ $num1 -gt $num2 ] && { echo "$num1 > $num2" } root@cs:/server/scripts# sh int.sh pls input two num:6 3 6 > 3 root@cs:/server/scripts# sh int.sh pls input two num:3 6 3 < 6 root@cs:/server/scripts# sh int.sh pls input two num:6 6 6 = 6 root@cs:/server/scripts# sh int.sh pls input two num:dd ff pls input two num again root@cs:/server/scripts# cat int1.sh #!/bin/bash num1=$1 num2=$2 [ $# -ne 2 ] && { echo "USAGE:$0 num1 num2" exit 1 } expr $num1 + 1 &>/dev/null RETVAL_n1=$? expr $num2 + 1 &>/dev/null RETVAL_n2=$? [ $RETVAL_n1 -eq 0 -a $RETVAL_n2 -eq 0 ] || { echo "pls input two num again" exit 2 } [ $num1 -lt $num2 ] && { echo "$num1 < $num2" exit 0 } [ $num1 -eq $num2 ] && { echo "$num1 = $num2" exit 0 } [ $num1 -gt $num2 ] && { echo "$num1 > $num2" } root@cs:/server/scripts# sh int1.sh 6 3 6 > 3 root@cs:/server/scripts# sh int1.sh 3 6 3 < 6 root@cs:/server/scripts# sh int1.sh 3 3 3 = 3 root@cs:/server/scripts# sh int1.sh dd ff pls input two num again
2021年04月04日
339 阅读
0 评论
0 点赞
2021-04-03
Shell:变量数值计算(下)
bc 命令用法如果没有安装bc,用下面命令进行安装centos systemctl intall -y bcUnbunt apt-get install -y bcroot@cs:/server/scripts# echo 3+5|bc 8 root@cs:/server/scripts# echo 3-5|bc -2 root@cs:/server/scripts# echo 3.6-5.2|bc -1.6 root@cs:/server/scripts# echo 3.6*5.2|bc 18.7 root@cs:/server/scripts# echo "scale=2;355/113"|bc 3.14 root@cs:/server/scripts# echo "scale=6;355/113"|bc 3.141592计算1-10的结果root@cs:/server/scripts# echo `seq -s "+" 10`=`seq -s "+" 10|bc` 1+2+3+4+5+6+7+8+9+10=55 root@cs:/server/scripts# echo `seq -s "+" 10`=$((`seq -s "+" 10`)) 1+2+3+4+5+6+7+8+9+10=55 root@cs:/server/scripts# echo `seq -s '+' 10`=$(echo $[`seq -s "+" 10`]) 1+2+3+4+5+6+7+8+9+10=55 awk实现计算root@cs:/server/scripts# echo "5.3 6.9"|awk '{print ($1+$2)}' 12.2 root@cs:/server/scripts# echo "5.3 6.9"|awk '{print ($1-$2)}' -1.6 root@cs:/server/scripts# echo "5.3 6.9"|awk '{print ($1*$2)}' 36.57 root@cs:/server/scripts# echo "5.3 6.9"|awk '{print ($1/$2)}' 0.768116$[]实现运算root@cs:/server/scripts# i=8 root@cs:/server/scripts# i=$[i+6] root@cs:/server/scripts# echo $i 14 root@cs:/server/scripts# echo $[i-5] 9 root@cs:/server/scripts# echo $[i*5] 70 root@cs:/server/scripts# echo $[i**5] 537824 root@cs:/server/scripts# echo $[i/5] 2 root@cs:/server/scripts# echo $[i%5] 4基于Shell 变量输入read 命令的运算实践root@cs:/server/scripts# cat test3.sh #!/bin.bash read -p "please input two:" a b echo "a+b=$(($a+$b))" echo "a-b=$(($a-$b))" echo "a*b=$(($a*$b))" echo "a/b=$(($a/$b))" echo "a**b=$(($a**$b))" echo "a%b=$(($a%$b))" echo "a++:$((a++))" echo "a=$a" echo "++a:$((++a))" echo "a=$a" echo "b--:$((--b))" echo "b=$b" echo "--b:$((--b))" echo "b=$b"执行结果root@cs:/server/scripts# sh test3.sh please input two:2 2 a+b=4 a-b=0 a*b=4 a/b=1 a**b=4 a%b=0 a++:2 a=3 ++a:4 a=4 b--:1 b=1 --b:0 b=0完善的代码root@cs:/server/scripts# cat test3.sh #!/bin.bash read -t 15 -p "please input two:" a b [ ${#a} -le 0 ]&&{ echo "the first num is null" exit 1 } [ ${#b} -le 0 ]&&{ echo "the first num is null" exit 1 } expr $a + 1 &>/dev/null REVTAL_A=$? expr $b + 1 &>/dev/null REVTAL_B=$? if [ $REVTAL_A -ne 0 -o $REVTAL_B -ne 0 ];then echo "one of the num is not num,pls input again." exit 1 fi echo "a+b=$(($a+$b))" echo "a-b=$(($a-$b))" echo "a*b=$(($a*$b))" echo "a/b=$(($a/$b))" echo "a**b=$(($a**$b))" echo "a%b=$(($a%$b))" echo "a++:$((a++))" echo "a=$a" echo "++a:$((++a))" echo "a=$a" echo "b--:$((--b))" echo "b=$b" echo "--b:$((--b))" echo "b=$b"运算结果root@cs:/server/scripts# sh test3.sh please input two:12 12 a+b=24 a-b=0 a*b=144 a/b=1 a**b=8916100448256 a%b=0 a++:12 a=13 ++a:14 a=14 b--:11 b=11 --b:10 b=10用传参方式进行运算
2021年04月03日
310 阅读
0 评论
0 点赞