shell趣味编程:case语句判断字符串内容

#!/bin/bash
#
#case语句:
#1,判断首字符是否为字⺟母
#2,判断输入内容是否全部是数字

declare -i switch=0
str=$1
for i in `seq 0 ${#str}`;do
    var=`echo ${str:$i:1}`
    case $var  in
    [a-zA-Z])
            if [ $i -eq 0 ];then
                echo "first character is a alpha"
            fi

            switch=1
        ;;
    [0-9])

        ;;
    *)
            if [ $switch -eq 0  ];then
            echo "Total digit"
            fi
        exit 1
    esac
done

你可能感兴趣的:(Linux-系统运维)