自己寫了一下小的shell實例,雖然很小,但所有的大的程序都是由小的模塊堆積起來的,程序員一定要懂得一種腳本的書寫,而我,只會在linux下工作,所以就只能寫linux的shell腳本了,呵呵,本文會陸續更新,給自己加油!
1.模擬linnux登錄shell
 代碼如下:
#/bin/bash
echo -n "login:" 
read name
echo -n "password:"
read passwd
if [ $name = "cht" -a $passwd = "abc" ];then
echo "the host and password is right!"
else echo "input is error!"
fi
2.比較兩個數大小
 代碼如下:
#/bin/bash
echo "please enter two number"
read a
read b
if test $a -eq $b
then echo "NO.1 = NO.2"
elif test $a -gt $b
then echo "NO.1 > NO.2"
else echo "NO.1 < NO.2" 
fi
3.查找/root/目錄下是否存在該文件
 代碼如下:
#/bin/bash
echo "enter a file name:"
read a
if test  -e /root/$a 
then echo "the file is exist!"
else echo "the file is not exist!"
fi
4.for循環的使用
 代碼如下:
#/bin/bash
clear
for num in 1 2 3 4 5 6 7 8 9 10
do
    echo "$num"
done
5.
 代碼如下:
#/bin/bash
echo "Please enter a user:"
read a
b=$(whoami)
if test $a = $b
then echo "the user is running."
else echo "the user is not running."
fi
6.刪除當前目錄下大小為0的文件
 代碼如下:
#/bin/bash
for filename in `ls`
do
    if test -d $filename
    then b=0
    else    
       a=$(ls -l $filename | awk '{ print $5 }')
            if test $a -eq 0
             then rm $filename
             fi
        fi      
done
7.如果/export/um_lpp_source下有文件,那么將其文件系統大小改為3G
 代碼如下:
#/bin/bash
while line=`ls /export/um_lpp_source`
do
        if test $line=""
        then  echo "NULL"
             sleep 1
    else echo $line
                chfs -a size=3G /export/um_lpp_source
                 exit 0
        fi
done
 
8.測試IP地址
 代碼如下:            
新聞熱點
疑難解答