如上最近在練習SHELL可是想要的功能一直無法出來
程式碼如下
#!/bin/bash
read -p "you input address : " x
if [ ${x} -gt 3 ]
then
echo "this math onle therr"
exit 3
fi
*if [ ${x} == [:alpha:] ]
then
echo "this is only math"
exit 4
fi *
read -p "you postic : " c
if [ ! -e ${c} ]
then
echo ${c}"is no exist"
exit 5
fi
echo ${c} 192.168.1.${x}/24"(rw,sec=krb5p)" > /test/nfs
我想要的功能是
當X輸入不是數字的時候會跳出提醒並且結束
請問該修改哪裡呢
~
read -p "you input address : " x
if ! [[ "${x}" =~ ^[0-9]+$ ]]
then
echo "this is only math"
exit 4
elif [ ${x} -gt 3 ]
then
echo "this math onle therr"
exit 3
fi
read -p "you postic : " c
if ! [ -e "${c}" ]
then
echo ${c} "is no exist"
exit 5
fi
echo ${c} 192.168.1.${x}/24"(rw,sec=krb5p)" > /test/nfs
第一次寫