Forum Moderators: bakedjake
A couple of problems there:
1. -ge expects an integer argument, and causes an error if it doesn't get one.
2. That would rule out -ve integers as arguments.
I'm playing with this case structure:
case $xx in
[0-9]) echo integer;;
*) echo "not integer";;
esac
..but I dont know how to match {any amount of [0-9], but nothing else }
..and I don't know how to handle the minus sign either!
How about:
case $xx in
[a-z]) echo Not integer
;;
*) echo "integer";;
esac
Where it says a-z, put in everything that's not an int, and the * will catch everything else (that's hopefully an int), of any size...
Or:
case $xx in
[0-9,-]) echo integer;;
[0-9,-][0-9]) echo integer;;
[0-9,-][0-9][0-9]) echo integer;;
[0-9,-][0-9][0-9][0-9]) echo integer;;
[0-9,-][0-9][0-9][0-9][0-9]) echo integer;;
*) echo "not integer";;
esac
ad nauseam.
A couple (or more) queries:
1. When I was using the case structure [0-9]* was matching strings like 123abc, as [0-9].* is supposed to.
2. Does this explain the first * in (*[0-9]*) ..?
(All the refs I find say: [0-9]* matches any number {there's only 1 * there!})
3. Any idea how to match a minus sign too?
http://etext.lib.virginia.edu/helpsheets/regex.html [etext.lib.virginia.edu]
That will probably help you along.
But, here's one that I found:
#!/usr/local/bin/bash
x=$1
case $x in
*[!0-9+-]*¦?*[-+]*¦""¦-¦+) echo Is not an integer;;
*) echo Is an integer;;
esac
Fun!
-MM