![]() |
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 |
| awk: How do i check to see if a variable is a number? | natdeamer | Shell Programming and Scripting | 1 | 09-06-2007 07:31 AM |
| how to search string and number in one file and check in the other file | knshree | Shell Programming and Scripting | 9 | 08-24-2007 04:29 AM |
| read string, check string length and cut | ozzy80 | Shell Programming and Scripting | 9 | 03-21-2007 05:56 PM |
| check whether variable number or string | rolex.mp | UNIX for Dummies Questions & Answers | 4 | 02-22-2007 12:12 AM |
| Check if variable is a number | handak9 | UNIX for Dummies Questions & Answers | 2 | 03-01-2005 08:27 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
||||
|
How to check whether a string is number or not
Hi ,
I am facing a problem .. which looks simple... but took 2 days of mine.. even now it is not solved completely.. I have one variable..., want to know whether that variable contains number... canbe +ve or -ve ... Values +35 --- number -43 --- number 45A -- non number 34+45 -- non number please help me Shihab |
|
|||||
|
Quote:
A small edit Shihab, #!/bin/ksh echo "Enter val : \c" read num expr "$num + 1" 2> /dev/null if [ $? = 0 ] then echo "Val was numeric" else echo "Val was non-numeric" fi Note the double qutoes around the expression. Rishi |
|
||||
|
how abt this,
Code:
[[ `echo $num | sed 's/^[-+0-9][0-9]*//' | wc -c` -eq 1 ]] && echo "itz number" && exit 0 echo "itz not number" plz let me know, if it faints somewhere |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|