摘要:
实战1:检查服务器运行状态脚本 [root@tzPC ~]# cat check.sh #!/bin/bash if [ $# -ge 1 ] ;then systemctl status $1 > /dev/null if [ $? -eq 0 ];then echo "$1 服务正在运行!" e 阅读全文
摘要:
使用if-then语句 语法格式 if command then commands fi 注意:if是根据命令退出码来判断(echo $?=0),如果是0,则表示为真,执行后面的命令 举例 [root@tzPC ~]# cat if-1.sh #!/bin/bash if ls /mnt then 阅读全文
摘要:
读取参数 位置参数变量是标准的数字 $0是脚本名 $1是第一个参数 $2是第二个参数 ... 每个参数都是用空格分隔,如果参数值有空格需要使用引号(单双引号都行) 如果要获取第10个参数及其以上需要加上花括号如${10} [root@tzPC 14Unit]# bash test4.sh 1 2 3 阅读全文