L6 Shell

写出以下shell脚本
1 判定一个用参数指定的文件是否为可执行,如果不是,则改为可执行#!/bin/bash

if [ -x $1 ]
then echo "OK"
else
echo "chmod a+x"
chmod a+x $1
fi

 

image
2 用while和until循环,实现输出某年前9个月月历的效果


#!/bin/bash
n=1;
while [[ $n -lt 10 ]] ;
    do
        cal $n $1;
        ((n++));
done;
image

 

#!/bin/bash
n=1;
until [[ $n -gt 9 ]];
do
echo $n
cal $n $1
((n++));
done ;

image

 


3 使用here文档写一个脚本,来实现删除某个指定文件时不用回答yes or no而直接删除,限定不能使用rm的-f开关

 

#!/bin/bash
rm $1 << EOF
yes
EOF

 

使用脚本删除output.sh

image


4 写一个脚本,可以输出用参数指定的年,以及该年中某几个用参数指定的月的月历,月的个数是不固定的

#echo $year
shift
for i
do
cal $i $year
done

image

posted @ 2014-07-20 22:57  hmilyjch  阅读(188)  评论(0编辑  收藏  举报