练习 2、写一个脚本/root/bin/yesorno.sh,提示用户输入yes或no,并判断用户输入的是yes还是no,或是其它信息 #!/bin/bash # case $1 in yY]|[yY][eE][Ss]) echo "you put a $1" ;; [nN]|[nN][Oo]) echo "you put a $1" ;; *) echo "ukown" ;; esac esca 3、写一个脚本/root/bin/filetype.sh,判断用户输入文件路径,显示其文件类型(普通,目录,链接,其它文件类型) #!/bin/bash # read -p "please input a file" FILE if [ -h $FILE ] ; then echo "filetype is symolink file" elif [ -d $FILE ] ;then echo "filetype is directory" elif [ -f $FILE ] ;then echo "common file." else echo "filetype is other" fi 4、写一个脚本/root/bin/checkint.sh,判断用户输入的参数是否为正整数 #!/bin/bash # if [[ $1 =~ ^0*[1-9][0-9]*$ ]] ;then echo "you have input a zhengshu" else echo "wrong" fi
本文出自 “mylinux” 博客,谢绝转载!
原文地址:http://luxiangyu.blog.51cto.com/9976123/1837414