if statement with '&&' gives error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting if statement with '&&' gives error
# 1  
Old 03-14-2012
if statement with '&&' gives error

Hi, I'm using the && operator in if statement:

Code:
if [ -d $DUMP && -d $LOG &&  "$PARALLEL_EXPORT" = "n" ]; then

exp $UID/$PWD@$ORACLE_SID FILE=./DUMP/$TODAY$CONCAT_STR$USERNAME.dmp STATISTICS=NONE LOG=./LOG/$TODAY$CONCAT_STR$USERNAME.log

elif [ -d $DUMP && -d $LOG &&  "$PARALLEL_EXPORT" = "y" ]; then

expdp $UID/$PWD@$ORACLE_SID DIRECTORY=./DUMP/ DUMPFILE=$TODAY$CONCAT_STR$USERNAME.dmp LOGFILE=./LOG/$TODAY$CONCAT_STR$USERNA
ME.log

else
        mkdir DUMP LOG
fi

It gives me an error:
./test2: test: ] missing

Please help me to resolve this error.

Thanks,
Priya
# 2  
Old 03-14-2012
use [[ ( double square brackets )

Code:
 
bash-3.2$ [ -d one.txt && -d two.txt ] && echo "Hi" || echo "TEST"      
bash: [: missing `]'
TEST
bash-3.2$ [[ -d one.txt && -d two.txt ]] && echo "Hi" || echo "TEST"
TEST

# 3  
Old 03-14-2012
now it gives error:
./test2: [[: not found

if [[ -d $DUMP && -d $LOG && "$PARALLEL_EXPORT" = "n" ]]; then

Is the above if statement is correct?
# 4  
Old 03-14-2012
which shell?
# 5  
Old 03-14-2012
#!/bin/sh
# 6  
Old 03-14-2012
try with bash

Code:
 
#!/bin/bash

---------- Post updated at 01:25 PM ---------- Previous update was at 01:20 PM ----------

otherwise, use -a for &&

Code:
 
[ -d one.txt -a  -d two.txt -a "$a" = "N" ] && echo "TEST" || echo "HI"

# 7  
Old 03-14-2012
'[[: not found' error in if statement

Now my script is:
Code:
#!/bin/sh
echo "Enter the EXPORT_LEVEL:(sys/system or user)"
read EXPORT_LEVEL
if [[ $EXPORT_LEVEL = "user" ]]; then
     echo "u r in if part"
else
        echo "u r in else part"
fi

whatever input i'm giving i.e. sys/system/user it always gives the output as:

./test4: [[: not found
u r in else part
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

2. Shell Programming and Scripting

Need Script to ZIP/SAVE & then DELETE Log file & send a mail conformation for any error

ENVIROMENT Linux: RHEL 6.4 Log Path: /usr/iplanet/servers/https-company/logs Log Format: user.log.03-15-2015 I have log4j log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I need a script that will run daily that... (1 Reply)
Discussion started by: admin_job_admin
1 Replies

3. Shell Programming and Scripting

Using && in if statement with 3 expressions

how do you write an if statement for something like if ((expr 1 >= expr 2 && expr 3 >= expr 4) && expr 5 <= expr 6) if ((TRUE && TRUE) && TRUE) then condition... i've done it this way but it doesn't seem to work. if (] && "$ex_day" -le "$curr_day" ); then condition... (3 Replies)
Discussion started by: angilulu
3 Replies

4. Shell Programming and Scripting

How to write If statement using && and operator in Unix

Hi What is the syntax for if statement using && and || operator? if && ] || here its giving me an error to this if statement any suggestion?? (2 Replies)
Discussion started by: Avi
2 Replies

5. Programming

IF && statement problem

Hello there, My first time on the forums, glad to be here :) I'm completely new to programming in PHP and I have a question which I hope someone could help me with. I am currently using this statement: if(($session == 2) && ($item == Dagger) && ($item2 == Dagger)){ ... (5 Replies)
Discussion started by: Hero
5 Replies

6. Shell Programming and Scripting

Replace & sign to &amp word

Hi, I have text file abc.txt. In this file, I have the following data. Input: Mr Smith &amp Mrs Smith Mr Smith &apos Mrs Smith Mr Smith & Mrs Smith Mr Smith& Mrs Smith Mr Smith &Mrs Smith Output: Mr Smith &amp Mrs Smith Mr Smith &apos Mrs Smith Mr Smith &amp Mrs Smith Mr Smith&amp... (4 Replies)
Discussion started by: naveed
4 Replies

7. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP. I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies

8. Linux

Kernal panic error& setuproot:error mounting /proc&/sys

Hi all, I am new to redhat/fedora linux. In fedora linux 6,we created one file system(hda3 - /fs). in this mount poing we were installed mounta vista os. while booting we are getting below error messages. 1) Booting 'mountaVisat(2.6.18_pro 500_pc_target-x86_586 smp)' root(hd0,1)... (2 Replies)
Discussion started by: arjunreddy3
2 Replies

9. Shell Programming and Scripting

using && in if statement ..

Hi All, Can some one tell me how to get run the following: data1="hello" data2="world" if then { echo "good afternnon" } else { echo " good morning" } fi The above code gives me an error ad below : ./if.h: line 3: ' (7 Replies)
Discussion started by: jisha
7 Replies

10. Shell Programming and Scripting

if statement with two conditions -e, &&

Wow I'm so zoned out I don't even know if I posted this question up already (I couldn't find it in my book marks or in "yesterday's" post). My question is, I'm writing a korn script that does something like the following, but I don't yet completely understand the syntax. I need to check that... (16 Replies)
Discussion started by: yongho
16 Replies
Login or Register to Ask a Question