#!/bin/bash DIR="/media/cdrom" if [ ! -d $DIR ] then mkdir -p $DIR fi
1 2 3 4 5 6 7 8
#!/bin/bash ping -c 3 -i 0.2 -W 3 $1 &> /dev/null if [ $? -eq 0] then echo"Host $1 is On-line." else echo"Host $1 is Off-line" fi
/dev/null 是一个 Linux 和 Unix 系统中的特殊文件,它表示一个黑洞,即一个没有任何内容、不产生任何输出、不接收任何输入的空文件。
这个文件通常用于在执行命令时将其输出重定向到该文件,或者在执行命令时将其输入重定向到该文件,从而防止输出或输入对其他程序产生影响。
1 2 3 4 5 6 7 8 9 10 11
#!/bin/bash read -p "Enter your score (0-100): " GRADE if [ GRADE -lt 1 ] ; then echo"error input!" elif [ $GRADE -ge 85 ] && [ $GRADE -le 100 ] ; then echo"$GRADE is Excellent" elif [ $GRADE -ge 70 ] && [ $GRADE -le 84 ] ; then echo"$GRADE is Pass" else echo"$GRADE is Fail" fi
for 条件循环语句
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/bin/bash # 批量添加用户 read -p "Enter The Users Password: " PASSWD for UNAME in `cat users.txt` do id$UNAME &> /dev/null if [ $? -eq 0 ] then echo"$UNAME, Already exists" else useradd $UNAME &> /dev/null echo"UNAME &> /dev/null echo "$UNAME, Create success" fi done
while条件循环语句
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/bin/bash PRICE=RANDOM % 1000) TIMES=0 echo"price is between 0 and 999, guess what?" whiletrue do read -p "input your predication: " INT let TIMES++ if [ PRICE ] ; then echo"congratulations, it's $PRICE" echo"you totally costs $TIMES times" exit elif [ PRICE ] ; then echo"too high" else echo"too low" fi done
[slacr@bogon ~]$ at -l warning: commands will be executed using /bin/sh at> systemctl restart httpd at> <EOT> job 1 at Fri Oct 6 23:30:00 2023 [slacr@bogon ~]$ at -l 1 Fri Oct 6 23:30:00 2023 a slacr