1.写一个脚本,执行后,打印一行提示“Please input a number:",要求用户输入数值,然后打印出该数值,然后再次要求用户输入数值。直到用户输入"end"停止。
#!/bin/sh
unset var
while [ "$var" != "end" ]
do
echo -n "please input a number: "
read var
if [ "$var" = "end" ]
then
break
fi
echo "var is $var"
done
2.写一个脚本,可以根据参数文件名,以正确的参数调用tar来解压缩tar.gz或tar.bz2文件。
#!/bin/sh
case ${1##*.tar.} in
bz2)
tar jxvf $1
;;
gz)
tar zxvf $1
;;
*)
echo "wrong file type"
esac
3.写一个脚本以方便用户查询rpm的相关信息。这个脚本首先提示用户选择查询依据,比如文件名,包名,全部等。然后提示用户选择查询信息,比如包名,包里所包含的所有文件,包的信息等。然后询问是否继续查询,是则循环刚才的过程,否则退出。
#!/bin/sh
RPM=/bin/rpm
option="-q"
while true
do
echo "what to query?"
select var in "All" "file" "package name"
do
case $var in
All)
option=$option"a"
break
;;
file)
echo -n "please input file name: "
option=$option"f"
read argument
break
;;
package name)
echo -n "please input package name: "
read argument
break
;;
*)
echo "please choose between 1-3"
;;
esac
done
echo "what do you want to know?"
select var in "location" "info" "package name"
do
case $var in
location)
option=$option"l"
break
;;
info)
option=$option"i"
break
;;
package name)
break
;;
*)
echo "please choose between 1-3"
;;
esac
done
${RPM} $option $argument
echo "continue? [yes/no]"
read answer
if [ answer = "no" ]
then
break
fi
done
阅读(1241) | 评论(1) | 转发(0) |