If statement advice


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If statement advice
# 1  
Old 12-17-2013
If statement advice

Hi all,
Need some advice.

I am attempting to write a if statment, to check a varaibale, but the output of the variable is empty (which is correct), but i am having issues write a if expression for this empty variable.

Can you please advice.


If statement - Output below
Code:
  if [[ $FRAG_DUP_LTO5_1 -eq 1 || $FRAG_DUP_LTO5_2 -eq 1 ]];  then
      if [[ $FRAG_LTO3_COPY_1 == "" && $FRAG_LTO3_COPY_2 == "" ]] ; then


Output of variable
Code:
+ bpimagelist -backupid ibl_1357326073
+ grep 'FRAG '
+ awk '{print $2,$9}'
+ sort -u
+ awk '{ if (L!=$1) print; L=$1}'
+ egrep -vi '\<C5|\<C6|\<W5|\<W6'
+ awk NR='=1{print $1}'
+ FRAG_LTO3_COPY_1='' 
+ bpimagelist -backupid ibl_1357326073
+ grep 'FRAG '
+ awk '{print $2,$9}'
+ sort -u
+ awk '{ if (L!=$1) print; L=$1}'
+ awk NR='=2{print $1}'
+ egrep -vi '\<C5|\<C6|\<W5|\<W6'
+ FRAG_LTO3_COPY_2=''
+ bpimagelist -backupid ibl_1357326073
+ grep 'FRAG '
+ awk '{print $2,$9}'
+ sort -u
+ awk '{ if (L!=$1) print; L=$1}'
+ egrep -i '\<C5|\<C6\<W5|\<W6'
+ awk NR==1
+ wc -l
+ FRAG_DUP_LTO5_1=0
+ bpimagelist -backupid ibl_1357326073
+ grep 'FRAG '
+ awk '{print $2,$9}'
+ sort -u
+ awk '{ if (L!=$1) print; L=$1}'
+ egrep -i '\<C5|\<C6\<W5|\<W6'
+ wc -l
+ awk NR==1
+ FRAG_DUP_LTO5_2=0
+ echo ''


Output of the if statement
Code:
+ [[ 0 -eq 1 ]]
+ [[ 0 -eq 1 ]]
+ [[ '' -eq 0 ]]

# 2  
Old 12-17-2013
Try using -z in your if statement to check for a null value in a variable:

Code:
if [ -z $VARIABLE ]

This User Gave Thanks to in2nix4life For This Post:
# 3  
Old 12-17-2013
Hello,

You can use the man test command to check further about the same.
Code:
if [[ -z $variable ]] ## Will be true in case variable having no value/values.
 
OR
 
if [[ -n $variable ]] ## Will be true in case variable having value/values.


Also it is be adviced to keep always values variables not hardcoded. Hardcoding the values may cause the issue in case you need to change their values later in script.


Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

2. Shell Programming and Scripting

Need Advice

Guys, Can you tell me what value would additional knowledge of PERL and CGI scripting will add to my skill set of UNIX shell scripting and ORACLE PL/SQL? I understand that PERL is a good tool for text processing. (1 Reply)
Discussion started by: yabhi_22
1 Replies

3. AIX

Need career advice please

Hi all, I'm a Solaris/linux sysadmin with a good general UNIX skills and with a little tiny background on AIX with no exposure to IBM's hardware ( just reading ) , but i think i can cope with it . UNIX jobs nowadays are rare here ( i mean hp-ux , solaris , aix ) not linux specially after the... (6 Replies)
Discussion started by: h@foorsa.biz
6 Replies

4. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

5. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies

6. Red Hat

Any advice would help

Hi everyone. I must admit up front that I am not very strong when it comes to Linux. I am actually a Windows guy, but don't let that count against me. :) I work for a very small company so we do not have a Server/Linux Admin on staff. Most of our needs have been handled by our WebHost. We have... (2 Replies)
Discussion started by: liquidstyleb
2 Replies

7. UNIX for Dummies Questions & Answers

need advice

i am currently running windows vista home premium, i want to install unix because i just started a computer programing course, i am just wondering if i install unix will i still have vista?? how does it work? will i get a choice of which os to run on system startup?? (1 Reply)
Discussion started by: naner9
1 Replies

8. Shell Programming and Scripting

Script Help/Advice

Alright, I feel like I have a pretty good basic knowledge of shell scripting, but this one is throwing me for a loop. I know I've seen something similar done with awk, but I couldn't find it with the search function. I've grepped through my log file and get results like this: --... (14 Replies)
Discussion started by: earnstaf
14 Replies

9. Shell Programming and Scripting

looking for advice...

Hi. First of all, Im an msoft guy, and when it comes to linux/unix, I'm retarded. Here is what I'm trying to do. I want to start I want to automatically connect to a remote server. Then I need it to login(https) -insert the licensce in the box(vi) -based on that licensce, the... (1 Reply)
Discussion started by: bravo24601
1 Replies

10. UNIX Desktop Questions & Answers

Looking for some advice

I am looking for some advice on wether to use unix or red hat linux? I have played with most windows OS and Mac OS up to in and including OS X. any and all advice would be appreciated (4 Replies)
Discussion started by: justawind
4 Replies
Login or Register to Ask a Question