how can i check that $1 is number...
HI ...
how can i check at cshell that $1 is number and not contain letters Thanks |
If the c-shell is like BASH, then numbers are stored as text strings.
echo $1 | grep -v [0-9] |
Thanks...
but this grep can' find $1 = 98y88 |
OOPS!!
grep -v [0-9] finds all lines that do not contain any numbers. grep -v [^0-9] finds all lines that do not contain any characters that are not numbers |
Quote:
Quote:
|
how can i set, if there is letters at $1
set b = 1 else set b = 0 ? Thanks again. |
I don't know anything about cshell (sorry).
But here are 3 different ways to do it in bash. Hope this helps you to translate it to cshell. Code:
if echo $0 | grep -q '^[0-9]*$'; then Code:
echo $0 | grep '^[0-9]*$' && b=1 || b=0 Code:
echo $0 | grep -qv '^[0-9]*$' |
Thanks for your effort
but i need it at cshell :) |
Quote:
|
if expr $1/1 == $1 then number else not a number
Should work at any shell. BTW, at least lookup the exact format for expr. ATB End |
@AnantaP,
Wont the expression fail if the field inside $1 is not a number? |
All times are GMT -5. The time now is 12:01 AM. |