Peter Nosko wrote:
-----Original Message-----
From: Charles Steinkuehler

To get around this problem (if necessary), you'll either need to recursively parse each digit of the parameter to see if it's a number (ugly, but relies only on built-in shell commands)...something like:

pn] Somehow I knew you'd reply in a jiffy! You are the Master of
Parameter Expansion! To make sure I understand it, the IF in ParseChar
says...


If the length of this number is >= 2 digits, send everything after the first digit back through Parse.

pn] Right?

You got it!


The ${#1} expands into the number of characters in the first positional parameter passed to ParseChar. If there's more than one character (ie greater than or equal to 2), ParseChar gets called again (recursive behavior), with the first character removed of the parameter in question removed (the ${1#?} strips the first character off of $1).

NOTE: Looking back over the code this morning, I'm noting that I didn't double quote the various parameter expansions. This means you could get incorrect results if you do something silly like: Parse "123 abc".

I also called Parse instead of ParseChar from within the case statement (a goof caused by renaming the procedures mid-way through writing the script). This doesn't really cause a major problem as the code stands, but it's more confusing than it should be, and causes potential interaction issues between Parse and ParseChar.

The revised version:

#!/bin/ash

ParseChar () {
case "$1"
 in
  [0-9]*)
    if [ "${#1}" -ge 2 ] ; then
      ParseChar "${1#?}"
    fi ;;
  *) NUMBER=NO ;;
esac
}

Parse () {
  NUMBER=YES
  ParseChar "$1"
}

Parse "$1"

echo "Number?: $NUMBER"

--
Charles Steinkuehler
[EMAIL PROTECTED]




------------------------------------------------------- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 ------------------------------------------------------------------------ leaf-user mailing list: [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/leaf-user SR FAQ: http://leaf-project.org/pub/doc/docmanager/docid_1891.html

Reply via email to