Relational operator


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Relational operator
# 1  
Old 09-13-2013
Relational operator

Hi guys ,

Code:
 
if a=12345678 i need to check that "a" 
less than 8 char
greater than 8 char
equal to 8 char
contain only numeric.

I done the above with seperate if condition to check and print the proper echo statement according to the result.i.e more than 8 char/lessthan etc..
can i able to check all the condtions in one if using OR operator and echo the proper output.
Anybody pls help me out.
Code:
 
OS:SUNOS
script:shell scripting

# 2  
Old 09-13-2013
Quote:
Originally Posted by mohanalakshmi
can i able to check all the condtions in one if using OR operator and echo the proper output.
Yes, you can do so. Check the man page of the test-command and have a look for the "-o" and "-a" options.

I hope this helps.

bakunin
# 3  
Old 09-15-2013
Code:
len=`echo "$a" | awk '{print length}'`
if [ $len -lt 8 ]
then
 echo "less than 8"
elif [ $len -gt 8 ]
then
 echo "greater than 8"
elif [ -z `echo "$a" | tr -d '[0-9]'` ]
then
 echo "8 digits"
else
 echo "8 characters"
fi

 
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Processing small database which is not relational

Hello, Decided to edit the whole post as nobody was replying, and it was pretty darn big as it was. So I have to write this script for my assignment, and I am new to scripting. The problem is we have to handle command line args, process an operations file which adds supermarket items to a database... (7 Replies)
Discussion started by: gcampton
7 Replies

2. UNIX for Advanced & Expert Users

Relational Join (Composite Key)

hi, i have file 1: ====== 0501000|X1 0502000|X2 0501231|X3 0981222|X4 0502000|X6 0503000|X7 0932322|X8 file 2: ======= 050 0501 0502 09 098 (1 Reply)
Discussion started by: magedfawzy
1 Replies
Login or Register to Ask a Question