-
例子:刪除用戶腳本
查看全部 -
批量添加指定數(shù)量的用戶
cat /etc/passwd 查看當(dāng)前所有用戶
查看全部 -
從一加到一百
查看全部 -
#!/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
查看全部 -
#!/bin/bash
read -t 10 -p "please input your choice yes/no: " choice
case $choice in
? ? ? ? ? "yes")
? ? ? ? ? ? ? ?echo "your choice is yes"
? ? ? ? ? ? ? ;;
? ? ? ? ? ?"no")
? ? ? ? ? ? ? ?echo "your choice is no"
? ? ? ? ? ? ? ;;
? ? ? ? ? ? *)
? ? ? ? ? ? ? ?echo "your choice is another"
? ? ? ? ? ? ? ;;
esac
查看全部 -
#!/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
查看全部 -
多分支if 條件語句
查看全部 -
#!/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
查看全部 -
?ps aux:查看系統(tǒng)中所有正在運行的進程,
?apache關(guān)鍵字
httpd grep -v grep:取反,不包含grep?
?判斷apache服務(wù)是否啟動? ? ps aux | grep httpd |grep -v grep
查看全部 -
#!/bin/bash
read? -t 10 -p "input your etcname" etcname
if [-d "$etcname"]
? ?then
? ? ?echo "yes"
? ?else
? ? ?echo "no"
fi
查看全部 -
#!/bin/bash
rate=$(df -h | grep "/dev/sda1" | awk '{print $5}' |? 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
查看全部 -
多重條件判斷
查看全部 -
字符串的判斷
查看全部
舉報