![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Converting integer to String | ROOZ | Shell Programming and Scripting | 1 | 06-05-2008 01:38 PM |
| conersting string to integer | abb058 | UNIX for Dummies Questions & Answers | 2 | 08-23-2006 07:52 AM |
| C function to test string or integer | qqq | High Level Programming | 3 | 03-10-2005 01:55 AM |
| Integer to String | psilva | High Level Programming | 2 | 08-17-2001 12:14 PM |
| convert from an integer to a string | mojomonkeyhelper | UNIX for Dummies Questions & Answers | 6 | 03-29-2001 04:15 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Checking if string contains integer
G'day guys, first post so be gentle.
I need help with some code to work out if a variable (string) contains any integers. The valid variable (string) must contain only letters. Also need to be able to work out if a variable contains only integers. Any help greatly appreciated. |
|
|||||
|
Welcome to the forums. We have a search feature which you can use to see if similiar problems have encountered before.
See - ksh : find value type |
|
||||
|
Sorry, should have specified it is a Bourne shell script that I am writing.
This is what I've tried writing, where am i going wrong? Code:
namenum=$1
if [ "$namenum" -eq *[a-zA-Z]* ] ; then
echo "$namenum is all alphabetic"
else
echo "not all alphabetic"
fi
|
|
||||
|
try "tr"
Do a man on tr basiclly # echo "AbCd67Fg8" | tr -d "[:alpha:]" # 678 So test for null variables ie #!/bin/sh var=AbCd67g8 if [ -z `echo $var | tr -d "[:alpha:]"` ] then echo "ONLY Alpha chars here!" # You had only A-z else echo "Sorry you have other stuff" # You have soming else besides A-z? fi |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|