【发布时间】:2010-12-25 20:29:37
【问题描述】:
我在 KornShell (ksh) 中有以下代码:
FAILURE=1
SUCCESS=0
isNumeric(){
if [ -n "$1" ]; then
case $1 in
*[!0-9]* | "") return $FAILURE;
* ) return $SUCCESS;
esac;
else
return $FAILURE;
fi;
}
#...
FILE_EXT=${FILE#*.}
if [ isNumeric ${FILE_EXT} ]; then
echo "Numbered file."
fi
#...
在某些情况下,文件名没有扩展名,这会导致FILE_EXT 变量为空,从而导致以下错误:
./script[37]: test: 0403-004 Specify a parameter with this command.
我应该如何调用这个函数,以免出现这个错误?
【问题讨论】:
-
我希望整个文件名都在 FILE_EXT 中而不是什么都没有,除非文件名以 '.' 结尾