checking the value of the variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting checking the value of the variable
# 1  
Old 06-12-2008
checking the value of the variable

Does anyone know the quick way to check if the variable contains only numeric characters, for example:
A=123445 - correct
B=#f123* - incorrect
I am in ksh88i Thanks a lot for help -A
# 2  
Old 06-12-2008
For integers:

Code:
case $var in 
  "" | *[!0-9]* ) echo invalid number ;;
              * ) echo OK ;;
esac

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking the file depending on the input variable

Hi I have a requirement of taking time as input variable outside the script.depending on the time it will check the file output .like ./script.sh <30 min> so script.sh should run every 5 minutes ie.6 times to check the output file.Can any one please help here. (7 Replies)
Discussion started by: netdbaind
7 Replies

2. Shell Programming and Scripting

Checking for null condition in a UNIX variable

i have this code for i in `cat sql_output.txt` do -- some script commands done sql_output.txt has 1 column with employee_ids If the sql_output.txt is null then the do loop should not execute. How can i implement this. for i in `cat sql_output.txt` If i is null or empty then ... (5 Replies)
Discussion started by: rafa_fed2
5 Replies

3. Shell Programming and Scripting

Checking the variable in UNIX

Hi, I have a file abc.txt as ABC,TYU,1.2566 AHG,GJJ,1.898 hgh,FGA,1.854 My program is reading each line and storing the values variables base_cy, quo_cy, ra_amt Need to validate each of them as in: base_cy and quo_cy should be a 3 character alphabet among A-Z, if it is lower case ... (1 Reply)
Discussion started by: infyanurag
1 Replies

4. UNIX for Dummies Questions & Answers

Checking the language variable

This is what I have just entered and received in return: # echo $LANG LANG: Undefined variable. How can this be? I was expecting something like en_US.utf8. Am using FreeBSD 8.2. (2 Replies)
Discussion started by: figaro
2 Replies

5. UNIX for Dummies Questions & Answers

checking wether an inputed character is already in a variable

Hi, i have a variable which holds a variety of letters. eg, var=qwertyuiop what i want to do is determine wether an inputed letter is already stored inside the variable, so i can say to enter a new one. i have been playing around using tr and grep but nothing seems to work at all. ... (2 Replies)
Discussion started by: castillo
2 Replies

6. Shell Programming and Scripting

checking variable has value - ksh

hi all, i have a shell (ksh) script where i am reading line by line from a grep command and i wanted to check if the grep command actually returned something or was null. i can do this by using -z : if ; then ..... but this forces me to do something when $myVariable is null when i... (3 Replies)
Discussion started by: cesarNZ
3 Replies

7. UNIX for Dummies Questions & Answers

ksh Checking if variable has 5 digits

How could I check if a numeric variable has 5 digits in KSH...I have a zipcode variable that I know will always be 5 digits, and I want to print out an error if it is less or more than 5 digits the problem is that I have it as: if ] but this won't work because the statement doesn't see 0001 as... (3 Replies)
Discussion started by: developncode
3 Replies

8. Shell Programming and Scripting

Eliminate variable checking in a script

RH Linux, $SHELL=/bin/ksh I have a .profile which I source in as such --> . .profile Whats happening is the variables are getting validated and generating errors. for example .profile export foo=/to/the/moon when I . .profile , I get : not foundmyusername/.profile or bad... (8 Replies)
Discussion started by: BMetelsky
8 Replies

9. Shell Programming and Scripting

checking valid values in variable

I'm using the following in my script. if echo $cpuidle |/usr/bin/egrep ; then when I issue this statement it issues the value of the variable back to stdout which ends up in my output file. Is there a better way to write this? I'm using ksh on solaris 9. (3 Replies)
Discussion started by: MizzGail
3 Replies

10. Shell Programming and Scripting

checking a variable is within range

how can i check that a variable is between 0-100, like if i ask a user to input a number between 1-100 and i want to excute commands WHILE that number is between that range or else i will keep asking the user to make another input here's what i got #!/bin/bash echo "Guess my secret number... (2 Replies)
Discussion started by: Poison Ivy
2 Replies
Login or Register to Ask a Question