check if a variable is not affected


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting check if a variable is not affected
# 1  
Old 03-17-2009
check if a variable is not affected

Hi all,

to check that a variable is not empty, I usually do:

if [ -z "$a" ]; then...
or
if [ -n "$a" ]; then...


what if I have a serie of variables and want to do the same test on all of them. How to do this in a single if statement?

thank you
# 2  
Old 03-17-2009
You can try using loops. For eg:

Code:
for i in <list of variables>
do
  if [ -z $i ] then
    do something;
  else
    do something;
done

HTH,Smilie

Regards,

Praveen
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Cybersecurity

The Heartbleed Bug - What versions of the OpenSSL are affected?

Reference: The Heartbleed Bug What versions of the OpenSSL are affected? Status of different versions: OpenSSL 1.0.1 through 1.0.1f (inclusive) are vulnerable OpenSSL 1.0.1g is NOT vulnerable OpenSSL 1.0.0 branch is NOT vulnerable OpenSSL 0.9.8 branch is NOT vulnerable Bug was... (3 Replies)
Discussion started by: Neo
3 Replies

2. AIX

High CPU Usage , users affected

Dear All, One production Server is affected by high usage. Application is slow now. Please guide me how to solve it? NMON Report shows full cpu usage. Here im posting some server details. bash-3.2# lparstat -i Node Name : ********* Partition Name ... (6 Replies)
Discussion started by: Thala
6 Replies

3. Shell Programming and Scripting

Check variable

Hi people, I would like to start a review of my config variable to check whether they have been changed and if not then there is only an echo. If they have been changed to my other commands are executed. I hope you can help me. with best regards JPad edit: here my code if ;... (8 Replies)
Discussion started by: JPad
8 Replies

4. UNIX for Dummies Questions & Answers

Problem with FreeBSD 8.3. BIOS affected

Hello everybody. I have a problem of this kind: After installation of FreeBSD, my Windows XP became unreachable. Boot from CDROM is impossible. The conclusion: BIOS was damaged by GParted or some other program. Question: Are there any Unix means of updating (repairing) BIOS ?:wall: (11 Replies)
Discussion started by: prabux
11 Replies

5. Shell Programming and Scripting

Check if a variable is having value

I have a script /root/asas with following contents. #!/bin/bash ha=`cat /etc/passwd | grep sandra` if ; then echo "Sandra is in /etc/passwd" echo "variable ha is $ha" else echo "Sandra is NOT in /etc/passwd" echo "variable ha is $ha" fi What... (3 Replies)
Discussion started by: anil510
3 Replies

6. Shell Programming and Scripting

Check if a variable is zero

I have seen many posts for this sort of problem but I just did not know how to use it for my issue. A number is assigned to a variable and I wanted to check if it is a zero or non zero. Example of my numbers are below: 000000000000000000000000000000000000000000000000... (8 Replies)
Discussion started by: soujiv
8 Replies

7. What is on Your Mind?

Were You Affected by Volcanic Activity in Iceland?

If you were effected by the volcanic activity in Iceland, share you vote and story here. ---------- Post updated at 04:15 ---------- Previous update was at 04:10 ---------- A friend of mine in Tokyo had a contracting job with a film production company. They had to cancel an event because... (2 Replies)
Discussion started by: Neo
2 Replies

8. Shell Programming and Scripting

How to check if a variable contains a .

Hi I am writing a bash script and would like to check is a variable contains a . or not ex. a=102 output ok a=1.02 output not ok Many thanks, (3 Replies)
Discussion started by: gekkos
3 Replies
Login or Register to Ask a Question