If statement not matching correctly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If statement not matching correctly
# 1  
Old 07-16-2012
If statement not matching correctly

Hi,
When I run the below if statement it keeps returning a yes even though it should be returning a no.. I'm not sure why this is happening.. Can anyone shed some light.?

Code:
if [[ $PUB_FILES_PRESENT == "0" ]]
then 
echo "no"
else
echo "yes"
fi



Quote:
$ ls *.pub 2> /dev/null | wc -l
0
$ echo $PUB_FILES_PRESENT
0

This is being run via ksh on Solaris...
# 2  
Old 07-16-2012
Code:
if [[ "$PUB_FILES_PRESENT" = "0" ]]
then 
echo "no"
else
echo "yes"
fi

OR-------------
Code:
if [ $PUB_FILES_PRESENT -eq 0 ]                    #when you are comparing a variable
then 
echo "no"
else
echo "yes"
fi

I guess you are trying to check if there are any PUB files present .
Code:
directory="/ns/home/aash"
if [`ls "$directory"/*.PUB | wc -l 2>/dev/null` -eq 0 ]
then
echo no
else
echo yes
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to combine all matching dates and remove non-matching

Using the awk below I am able to combine all the matching dates in $1, but I can not seem to remove the non-matching from the file. Thank you :). file 20161109104500.0+0000,x,5631 20161109104500.0+0000,y,2 20161109104500.0+0000,z,2 20161109104500.0+0000,a,4117... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. 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

3. Shell Programming and Scripting

Compare file1 for matching line in file2 and print the difference in matching lines

Hello, I have two files file 1 and file 2 each having result of a query on certain database tables and need to compare for Col1 in file1 with Col3 in file2, compare Col2 with Col4 and output the value of Col1 from File1 which is a) not present in Col3 of File2 b) value of Col2 is different from... (2 Replies)
Discussion started by: RasB15
2 Replies

4. Shell Programming and Scripting

Pattern Matching in IF-ELSE statement

Hi all, I am trying to use an if statement to see whether a variable falls under any of the 5 patterns: if ] then echo "something" else echo "Please enter a correct division" fi The problem is despite having the variable DIV as "ter", "bom", "hre", "nte", or "mol" it will... (6 Replies)
Discussion started by: MIA651
6 Replies

5. Shell Programming and Scripting

Insert lines above matching line with content from matching

Hi, I have text file: Name: xyz Gender: M Address: "120_B_C; ksilskdj; lsudlfw" Zip: 20392 Name: KLM Gender: F Address: "65_D_F; wnmlsi;lsuod;,...." Zip:90233I want to insert 2 new lines before the 'Address: ' line deriving value from this Address line value The Address value in quotes... (1 Reply)
Discussion started by: ysrini
1 Replies

6. Shell Programming and Scripting

awk if statement matching all lines starting w/ a number

Does awk have a syntax for a range of numbers or is this the best way? if ($1 >= 0 && $1 <= 9 ) (7 Replies)
Discussion started by: Arsenalman
7 Replies

7. Shell Programming and Scripting

pattern matching in case statement

I have a file abc.sh which looks like qacc1 ----> down v5c0 check interface v5c1 I want to read this file line by line and perform a certain action if a particular pattern is found in that line. My code so far looks like this: FileName='abc.sh' while read LINE do echo $LINE case... (2 Replies)
Discussion started by: lassimanji
2 Replies

8. 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

9. 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

10. HP-UX

HP-UX will not boot correctly

i've same failure too, but this command boot pri isl not work/not found Thanks! (1 Reply)
Discussion started by: pantas manik
1 Replies
Login or Register to Ask a Question