您的位置:首页 > 其它

关于一级指针和二级指针作为参数的探究

2014-04-09 14:06 477 查看
#return 0 means input right, return 1 means input wrong
checkPort()
{
#check the input number

echo $1 | grep [^0-9] > /dev/null
if [ $? = 0 ]
then
echo "please input number."
return 1
fi;

echo $1 | grep ^[1-9] > /dev/null
if [ $? != 0 ]
then
echo "the first number should not be 0."
return 1
fi;

if [ $1 -gt $maxNumberPort ]
then
echo "the max number of the port should not more then $maxNumberPort."
return 1
fi;

if [ ! -z $2 ]
then
lsof -i:"$1" >>$log
if [ $? -eq 0 ]
then
echo "The port $1 has been used, please input another. "
return 1
fi
fi;

return 0
}

#return 0 means the path is ok, return 1 means the path has some errors
checkInstallPath()
{
installMaxLength=255
if [ $# != 1 ]
then
echo "please check the input parameters"
return 1
fi;

grep " " $1
if [ $? = 0 ]; then
echo " The install path can not contain bank ."
return 1
fi

echo "$installPath" | grep '[^-A-Za-z0-9._/]' > /dev/null
if [ "$?" = 0 ]; then
echo
echo -n "ISM cannot be installed in a directory containing special character in its name."
return 1;
fi

#deal with the relative path
#full path
firstChar=`echo "$1" | awk '{print substr($0,1,1)}'`
#if user input a relative path, then we will put "/" ahead of the path
if [ "$firstChar" != "/" ]; then
echo "please input full path!!"
return 1
fi

if [ ! -d $1 ]; then
echo "please make sure the directory exist."
return 1
fi

#check the length of the path
declare -i length
length=`echo "$1" | wc -m`
length=length-1
if [ $length -gt $installMaxLength ]; then
echo
echo -n "the max length of The installation path is 255"
return 1
fi

return 0
}

#return 0 means it is ok,return 1 means it has some formate error
checkIpAddress()
{

if [ $# != 1 ]
then
echo "please check the input parameter!!"
exit 1
fi;

ipSegLength=`echo $1 | awk -F [.] '{print NF}' `

if [ $ipSegLength != 4 ]
then
echo "ip formate error!!!"
return 1
fi;

arr=`echo $1 | awk -F [.] '{for(i=1;i<=NF;i++) printf("%s\n", $i)}'`

for i in $arr
do
echo $i | grep [^0-9] > /dev/null

if [ $? != 0 ]
then
echo "ip should only contains number!!!"
return 1
fi;

if [ $i > 255 || $i < 0 ]
then
echo "ip formate error!!"
return 1
fi;
done

return 0
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: