-
批量添加指定數量的用戶實例
查看全部 -
#!/bin/bash?
cd /root/test?
ls *.tar.gz > ls.log(>覆蓋)?
ls *.tgz >> ls.log(>>追加)?
for i in $(cat ls.log)?
????do?
????????tar -zxvf $i &> /dev/null?
????done?
rm -rf ls.log
查看全部 -
多分支語句case語句
查看全部 -
#!/bin/bash?
read -t 30 -p "Please input a file name:" file?
if [ -z "$file" ]?
????then?
????????echo "Error, please input a file name!"?
????????exit 11?
elif [ ! -e "$file" ]?
????then?
????????echo "Your input is not a file name!"?
????????exit 22?
elif [ -f "$file" ]?
????then?
????????echo "$file is a regular file!"?
elif [ -d "$file" ]?
????then?
????????echo "$file is a directory !"?
else?
????echo "$file is another file!"?
fi
查看全部 -
#!/bin/bash?
read -t 30 -p "Please input num1:" num1?
read -t 30 -p "Please input num2:" num2?
read -t 30 -p "Please input operator:" ope?
if [ -n "$num1" -a -n "$num2" -a -n "$ope" ]?
????then?
????????test1=$(echo $num1 | sed 's/[0-9]//g')?
????????test2=$(echo $num2 | sed 's/[0-9]//g')?
????????????if [ -z "$test1" -a -z "$test2" ]?
????????????????then?
????????????????????if [ "$ope" == '+' ]?
????????????????????????then?
????????????????????????????result=$(($num1+$num2))?
????????????????????elif [ "$ope" == '-' ]?
????????????????????????then?
????????????????????????????result=$(($num1-$num2))?
????????????????????elif [ "$ope" == '/' ]?
????????????????????????then?
????????????????????????????result=$(($num1 / $num2))?
????????????????????elif [ "$ope" == '*' ]?
????????????????????????then?
????????????????????????????result=$(($num1*num2))?
? ? ? ? ? ? ? ? ? ? else?
? ? ? ? ? ? ? ? ? ? ? ? echo "Error: the input operator is worng, please input +-*/"?
? ? ? ? ? ? ? ? ? ? ? ? exit 111?
????????????????????fi?
????????????????else?
????????????????????echo "Error: Please input numbers!"??
?????????????????? ?exit 222?
????????????????fi?
????????echo "$num1 $ope $num2 is $result"?
????else?
????????echo "Error: You input null value!"?
????????exit 333?
fi
查看全部 -
#!/bin/bash
test=$(ps aux | grep "httpd" | grep -v "grep")
if [ -n "$test" ]
????then
????????echo "httpd is on"
????else
????????echo "httpd is off"
????????/etc/rc.d/init.d/httpd start
fi
查看全部 -
#!/bin/bash
read -t 30 -p "please input a dir:" dir
if [ -d "dir" ]
????then
????????echo "yes"
????else
????????echo "no"
fi
查看全部 -
#!/bin/bash
rate=$(df -h | grep "/dev/sda1" | cut -d "%" -f 1)
if [ "$rate" -ge "80" ]
????then
????????echo "/dev/sda1 is full"
fi
查看全部 -
#!/bin/bash
test=$(env | grep "USER" | cut -d "=" -f 2)
if [ "$test" == "root" ]
????then
????????echo "Current user id root."
fi
查看全部 -
多重條件判斷
查看全部 -
字符串的判斷
查看全部 -
兩個整數之間的比較
查看全部 -
兩個文件之間的比較
查看全部 -
按文件權限判斷
查看全部 -
兩種判斷格式
test -e /root/abc
[ -e /root/abc ]
查看全部
舉報