zhangsanfeng88 发表于 2018-8-27 11:41:04

shell脚本练习基础篇2-mylinux

练习  

  
2、写一个脚本/root/bin/yesorno.sh,提示用户输入yes或no,并判断用户输入的是yes还是no,或是其它信息
  
#!/bin/bash
  
#
  
case $1 in
  
   yY]|)
  
         echo "youput a $1"
  
          ;;
  

  
|)
  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**$ ]] ;then
  
    echo "you have input a zhengshu"
  
    else
  
      echo "wrong"
  
    fi


页: [1]
查看完整版本: shell脚本练习基础篇2-mylinux