当前位置: 技术问答>linux和unix
shell中的正则表达式问题(很简单,大家过来接分)
来源: 互联网 发布时间:2016-06-12
本文导语: 一个shell脚本,我想让传的参数中只要含有非大写字符就打印“Sorry it's not upper case”,全是大写字符才显示“Great it's upper case”。可是我测试发现我输入小写字符“abcd”,也打印“Great it's upper case”。 #!/bin/s...
一个shell脚本,我想让传的参数中只要含有非大写字符就打印“Sorry it's not upper case”,全是大写字符才显示“Great it's upper case”。可是我测试发现我输入小写字符“abcd”,也打印“Great it's upper case”。
#!/bin/sh
is_upper()
{
if [ $# -ne 1 ]; then
echo "is_upper: I need a string to test OK"
return 1
fi
_IS_UPPER=`echo $1 | awk '{if($0~/[^A-Z]/) print "1"}'`
if [ "$_IS_UPPER" != "" ]
then
return 1
else
return 0
fi
}
echo -n "Enter the filename :"
read FILENAME
if is_upper FILENAME; then
echo "Great it's upper case"
else
echo "Sorry it's not upper case"
fi
问题解决,立马给分。
#!/bin/sh
is_upper()
{
if [ $# -ne 1 ]; then
echo "is_upper: I need a string to test OK"
return 1
fi
_IS_UPPER=`echo $1 | awk '{if($0~/[^A-Z]/) print "1"}'`
if [ "$_IS_UPPER" != "" ]
then
return 1
else
return 0
fi
}
echo -n "Enter the filename :"
read FILENAME
if is_upper FILENAME; then
echo "Great it's upper case"
else
echo "Sorry it's not upper case"
fi
问题解决,立马给分。
|
看起来并不简单。。。。。。。。。。。这分不好拿,哈哈哈
|
改成这样试试。
#!/bin/sh
is_upper()
{
if [ $# -ne 1 ]; then
echo "is_upper: I need a string to test OK"
return 1
fi
_IS_UPPER=`echo $1 | awk '{if($0~/[^A-Z]/) print "1"}'`
if [ "$_IS_UPPER" != "" ]
then
return 1
else
return 0
fi
}
echo -n "Enter the filename :"
read FILENAME
RTN=is_upper FILENAME
if [ $RTN -eq 1 ]; then
#if is_upper FILENAME; then
echo "Great it's upper case"
else
echo "Sorry it's not upper case"
fi
#!/bin/sh
is_upper()
{
if [ $# -ne 1 ]; then
echo "is_upper: I need a string to test OK"
return 1
fi
_IS_UPPER=`echo $1 | awk '{if($0~/[^A-Z]/) print "1"}'`
if [ "$_IS_UPPER" != "" ]
then
return 1
else
return 0
fi
}
echo -n "Enter the filename :"
read FILENAME
RTN=is_upper FILENAME
if [ $RTN -eq 1 ]; then
#if is_upper FILENAME; then
echo "Great it's upper case"
else
echo "Sorry it's not upper case"
fi
|
关注
学习
学习