当前位置: 技术问答>linux和unix
一个shell脚本问题
来源: 互联网 发布时间:2015-09-10
本文导语: 这是书上例子,执行后得不到预想的结果,想不明白. #!/bin/sh # isuptest echo -n "Enter the filename :" read FILENAME is_upper() # is_upper # to call: is_upper $1 { # check we have the right params if [ $# -ne 1 ]; then echo "is_upper: I need...
这是书上例子,执行后得不到预想的结果,想不明白.
#!/bin/sh
# isuptest
echo -n "Enter the filename :"
read FILENAME
is_upper()
# is_upper
# to call: is_upper $1
{
# check we have the right params
if [ $# -ne 1 ]; then
echo "is_upper: I need a string to test OK"
return 1
fi
# use awk to check we have only upper case
_IS_UPPER=`echo $1 | awk '{if($0~/[^A-Z]/) print "1"}'`
if [ "$_IS_UPPER" != "" ]
then
# no,they are not all upper case
return 1
else
# yes all upper case
return 0
fi
}
if is_upper $FILENAME ; then
echo "Great it's upper case"
# let's create a file maybe ??
else
echo "Sorry it's not upper case"
# shall we convert it anyway using str_ot_upper ??
fi
#!/bin/sh
# isuptest
echo -n "Enter the filename :"
read FILENAME
is_upper()
# is_upper
# to call: is_upper $1
{
# check we have the right params
if [ $# -ne 1 ]; then
echo "is_upper: I need a string to test OK"
return 1
fi
# use awk to check we have only upper case
_IS_UPPER=`echo $1 | awk '{if($0~/[^A-Z]/) print "1"}'`
if [ "$_IS_UPPER" != "" ]
then
# no,they are not all upper case
return 1
else
# yes all upper case
return 0
fi
}
if is_upper $FILENAME ; then
echo "Great it's upper case"
# let's create a file maybe ??
else
echo "Sorry it's not upper case"
# shall we convert it anyway using str_ot_upper ??
fi
|
什么是你预想的结果? 我执行的很正常啊