Korn Shell - Test with variable that may be not set
Posted
by C. Ross
on Stack Overflow
See other posts from Stack Overflow
or by C. Ross
Published on 2009-12-11T21:49:49Z
Indexed on
2010/04/25
6:13 UTC
Read the original article
Hit count: 262
I have the following code in KornShell
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
#...
In some cases the file name not have an extension, and this causes the FILE_EXT
variable to be empty, which causes the following error:
./script[37]: test: 0403-004 Specify a parameter with this command.
How should I be calling this function so that I do not get this error?
© Stack Overflow or respective owner