checking valid values in variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting checking valid values in variable
# 1  
Old 10-23-2006
checking valid values in variable

I'm using the following in my script.

if echo $cpuidle |/usr/bin/egrep [0-9][0-9]; 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.
# 2  
Old 10-23-2006
I don't know if I understand what you want, but couldn't you use the -q (quiet) option to suppress writing to stdout?
# 3  
Old 10-23-2006
Code:
if echo $cpuidle | grep -q  [0-9][0-9]; then

If you don't have -q option then use this

Code:
echo $cpuidle | grep [0-9][0-9] > /dev/null
if [ $? = 0 ]; then

# 4  
Old 10-23-2006
I had to use /usr/xpg4/bin/grep to get the -q option.
thanks, that works!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. SCO

How to measure disk IO 5.0.7? (sar, return values ​​are not valid)

Hello I am analyzing disk performance OSR5.0.7 running inside VirtualBox. GUEST: osr5.0.7; 1GB ram; raw disk HOST: SLES11SP3, 4GB ram; 1 disc SATA2-7200rpm But I'm not sure how to do it right (the values ​​returned by sar not match the values ​​of the physical machine) The attributes... (0 Replies)
Discussion started by: flako
0 Replies

2. Shell Programming and Scripting

Need a script to check if an argument is valid shell variable

I need a script that should print 'yes' if the argument is a valid shell variable name else 'No' if it is not a valid shell variable. A valid one begins with an alphabet or percentage (%) character and is followed by zero or more alphanumberic or percentage (%) characters. For example: $... (6 Replies)
Discussion started by: pingiliarjun
6 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. Shell Programming and Scripting

Valid date checking in the file

File contian below data... 20111101 20111102 20111131 I am new to unix and per scirpt... First two records are valid and last record is invalid,how to get the valid records... Please help me unix or perl script. :wall: Thanks, Murali (5 Replies)
Discussion started by: muralikri
5 Replies

5. Shell Programming and Scripting

Checking the Column values in a file.

Hi All, I have a file that has ~2.9Millions lines with 32 columns respectively. The columns numbers 23,27 are the primary Keys for the file. The fields are delimited by TAB. I need to check the condition If Column number: 20 is NOT NULL Column number: 21 is not 0 Column number: 22 is... (7 Replies)
Discussion started by: filter
7 Replies

6. Shell Programming and Scripting

Checking for a valid MAC Address

I have a ksh script and would like to validate a MAC address that is input by the user: 00:14:4F:FC:00:49 example: MAC=`/usr/bin/ckint -p "Enter MAC address"` echo $MAC echo " " Obviously chkint will not work, but does anyone have any suggestions? Thanks (9 Replies)
Discussion started by: hxman
9 Replies

7. Shell Programming and Scripting

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 (1 Reply)
Discussion started by: aoussenko
1 Replies

8. UNIX for Dummies Questions & Answers

checking parameter values passed to script

Hi, I will pass 3 parameters for a script.I have to check the file name and create a new file name with time stamp. the parameters which i'm passing are /dir/stg/filename.txt /dir/path/head.txt /dir/path/tail.txt Now i have to check filename like : if it is a.txt i have to create... (2 Replies)
Discussion started by: ammu
2 Replies

9. Shell Programming and Scripting

Checking the valid paths in the shell script

Hi i am using a shell script for renaming the files and placing in the remote location(FTP) my code is: cd $1 day=$(date +%d) for i in `ls -1 BBW*` do last=`tail -1 $i` pat=`expr "$last" : '.*(\(.*\)).*'` pat=`echo $pat | sed 's/ /_/'` pat=$pat$day mv $i $pat rm -f $day done... (3 Replies)
Discussion started by: srivsn
3 Replies

10. Shell Programming and Scripting

Code checking for all values in the same if statement.

I am trying to set up a variable based on the name of the file. function script_name { if then job_name='MONITOR' return job_name; elsif then job_name='VERSION' return job_name fi } for i in `ls *log` do script_name $i done. (4 Replies)
Discussion started by: oracle8
4 Replies
Login or Register to Ask a Question