![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ksh pattern matching | ripat | Shell Programming and Scripting | 5 | 02-10-2008 01:44 PM |
| help need for pattern matching | HIMANI | UNIX for Dummies Questions & Answers | 10 | 01-22-2008 04:30 AM |
| pattern matching | mercuryshipzz | Shell Programming and Scripting | 4 | 01-14-2008 08:01 PM |
| pattern matching | malle | Shell Programming and Scripting | 3 | 01-31-2007 02:23 AM |
| Pattern matching sed | leemjesse | Shell Programming and Scripting | 3 | 03-23-2005 01:06 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
pattern matching in an if-then
I'm having trouble getting my syntax right here; I want to test the value of $1 and return true if it is between 0 and 9. I've tried many combinations including
if [ $1 -eq [0-9] ] but none have worked when passing, say, "5" into $1. Any help is appreciated. Thanks. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
if [ "$1" -gt 0 ] && [ "$1" -lt 10 ] Code:
if (("$1" > 0)) && (("$1" < 10))
|
|
#3
|
|||
|
|||
|
Thanks for the reply. I think I may have done a lousy job of articulating my objective though. I'm looking to test for the presence of a non-numeric character; the above will produce an error. Perhaps that's the only way to do this, i.e. test for an error in a numeric operation?
Thanks again. |
|
#4
|
|||
|
|||
|
One way but it just says there exists a non-numeric:
Code:
#!/bin/ksh
check=$( echo "1234x6789" | tr -dc '[:alpha:]' )
if [[ ${#check} -gt 0 ]] ; then
echo 'found non-numeric'
else
echo 'all numbers'
fi
Code:
$(echo "1234x6789" | grep -q '[A-Z,a-z]') && echo 'found it' |
|
#5
|
|||
|
|||
|
Try:
Code:
case "$1" in [0-9]) echo "It's a digit!";; *) echo "Non-digit.";; esac |
|||
| Google The UNIX and Linux Forums |