Shell-练习1

#!/bin/sh
#This is to show what a example looks like.
echo "My First Shell!"
echo "This is current directory."
/bin/pwd
echo
echo "This is files."
/bin/ls 
#################################################

#!/bin/sh
/bin/date +%F >> /test/shelldir/ex2.info
echo "disk info:" >> /test/shelldir/ex2.info
/bin/df -h >> /test/shelldir/ex2.info
echo >> /test/shelldir/ex2.info
echo "online users:" >> /test/shelldir/ex2.info
/usr/bin/who | /bin/grep -v root >> /test/shelldir/ex2.info
echo "memory info:" >> /test/shelldir/ex2.info
/usr/bin/free -m >> /test/shelldir/ex2.info
echo >> /test/shelldir/ex2.info
#write root
/usr/bin/write root < /test/shelldir/ex2.info && /bin/rm /test/shelldir/ex2.info
#crontab -e
#0 9 * * 1-5 /bin /sh /test/ex2.sh
###################################################

#!/bin/sh
DATE=`/bin/date +%Y%m%d`
echo "TODAY IS $DATE"
/bin/ls -l $1
/bin/ls -l $2
/bin/ls -l $3

#####################################################

#!/bin/sh
DATE=`/bin/date +%F`
echo "today is $DATE"
echo '$# :' $#
echo '$* :' $*
echo '$? :' $?
echo '$$ :' $$
echo '$0 :' $0
#######################################################

#!/bin/sh
read f s t
echo "the first is $f"
echo "the second is $s"
echo "the third is $t"

##########################################################

#!/bin/sh
# if test $1 then ... else ... fi
if [ -d $1 ] 
then 
    echo "this is a directory!"
else
    echo "this is not a directory!"
fi
##############################################

#!/bin/sh
# if test  then ... elif test then ... else ... fi
if [ -d $1 ]
    then
    echo "is a directory!"
elif [ -f $1 ]
    then
    echo "is a file!"
else 
    echo "error!"
fi 
#############################################

#!/bin/sh
# -a -o 
if [ $1 -eq $2 -a $1 = 1 ]
    then
    echo "param1 == param2 and param1 = 1"
elif [ $1 -ne $2 -o $1 = 2  ]
    then
    echo  "param1 != param2 or param1 = 2"
else
     echo "others"
fi

##########################################

#!/bin/sh
# for var in [params] do ... done
for var in 1 2 3 4 5 6 7 8 9 10
do 
    echo "number is $var"
done

###############################

#!/bin/sh
read op
case $op in
        a)
     echo "you selected a";;
        b)
    echo "you selected b";;
    c)
    echo "you selected c";;
    *)
    echo "error"
esac
###########################################

#!/bin/sh
#while test do ... done

num=1
sum=0
while [ $num -le 100 ]
do
    sum=`expr $sum + $num`
    num=`expr $num + 1`
done
#sleep 5
echo $sum

#############################################

#!/bin/sh
i=0
while [ $i -le 100 ]
do
    i=`expr $i + 1`
    if [ $i -eq 5 -o $i -eq 10 ]
        then continue;
    else 
        echo "this number is $i"
    fi

    if [ $i -eq 15 ]
        then break;
        fi 
done

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值