#!/bin/bash if [ -e ~/test.sh ];then echo "test.sh文件存在" if [ -x ~/test.sh ];then echo "test.sh文件有执行权限" else echo "test.sh文件没有执行权限" fi else echo "test.sh文件不存在" fi
#!/bin/bash read -p "请输入你100米赛跑的秒数:" time if [ $time -gt 0 -a $time -le 10 ];then echo "恭喜你进入选拔赛" read -p "请输入你的性别(女或者男)" sex if [ $sex = '女' ];then echo "恭喜你进入女生组" elif [ $sex = '男' ];then echo "恭喜你进入男生组" else echo "输入有误!" fi elif [ $time -gt 10 ];then echo "很遗憾,你已被淘汰" else echo "输入有误,请重新输入" fi
#!/bin/bash case $1 in *.gz) tar zxvf $1 -C /opt ;; *.bz2) tar jxvf $1 -C /opt ;; *) echo "格式错误" ;; esac
#!/bin/bash # this is determine the odd number of documents read -p "请输入一个数: " num expr $num + 0 &> /dev/null if [ $? -eq 0 ];then echo "$num是整数!" a=$[ $num % 2 ] if [ $a -eq 0 ] then echo "$num是偶数" else echo "$num是奇数" fi else echo 你输入的不是整数! fi
#!/bin/bash #Determine whether the host is alive ping -c 3 -i 0.5 -w 2 $1 &> /dev/null if [ $? -eq 0 ];then echo "host is online" else echo "host is offline" fi
使能够使用 service firewalld start|stop|restart|status 来管理firewalld服务,
要求如果命令选项不对,则提示 “用法: $0 {start|stop|status|restart}”。
#!/bin/bash #Administrative firewalld read -p "请输入管理防火墙的需求(start|stop|restart|status):" need case $need in start) systemctl start firewalld echo "防火墙已开启" ;; stop) systemctl stop firewalld echo "防火墙已关闭" ;; restart) systemctl restart firewalld echo "防火墙已重启" ;; status) systemctl status firewalld echo "查看防火墙状态" ;; *) echo "用法: $0 {start|stop|status|restart}" esac