shell之常用的一些命令2
作者:互联网
前言
自我感觉学习shell要常用`man`,`--help`这样挺方便去写的,光靠熟练远远不够的
#!/bin/bash wget命令 我用到最多就是请求http网站啦,一般很少加参数 set -x url(){ timeout=6 fail=0 success=0 while true do wget --timeout=$timeout --tries=1 https://www.cnblogs.com/zqxFly/ -q -o /dev/null if [ $? -ne 0] then let fail=fail+1 else let success+=1 fi if [ $success -ge 1] then echo success exit 0 fi if [ $fails -ge 2] then ttry="sys is dowm" echo $ttry|tee|mail -s "https://www.cnblogs.com/xxx" exit 2 fi done } url wget 接http link expr 命令是一个手工命令行计数器 1.结合match进行整数判断 if [[`expr match "$1" "[0-9] [0-9]*$"` == 0 ] ] then echo "$1 is not a num" else echo "$1 is a num" fi 2.判断字符 expr $1 + 1 >/dev/null 2>&1 [ $? -eq 0 ] &&echo int || echo chars while true do read -p "hello adol":a expr $a + 0 >/dev/null 2>&1 [ $? -eq 0 ] && echo int || echo chars done 3.整数运算[ $# -ne 2 ] &&{ echo $"usage $0 num1 num2" exit 1 } a=$1 b=$2 expr $a + $b + 110 &>/dev/null if [ $? -ne 0 ] then echo "you must two nums" exit 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))" bc 命令是任意精度计算器语言 bc(选项)(参数) 通过管道符 echo "1.11+2" | bc 直接输入bc read命令用于从标准输入读取数值
标签:常用,shell,success,bc,expr,echo,命令,exit,fi 来源: https://www.cnblogs.com/zqxFly/p/15772352.html