LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Syntax Question for scripting - if conditions (https://www.linuxquestions.org/questions/linux-newbie-8/syntax-question-for-scripting-if-conditions-634061/)

jim.thornton 04-08-2008 09:25 PM

Syntax Question for scripting - if conditions
 
I'm getting a syntax error with this and was hoping for some help please:

if [[ -e $4 ] && [ "$overwrite_flag" != 0 ]] || [ -!e $4 ]

I'm trying to say:

(If file ($4) exists AND the overwrite flag is set) OR (If the $4 file does NOT exist) THEN ....


Can someone please tell me what i'm doing wrong?

PatrickNew 04-08-2008 09:41 PM

I would put the last condition first. The problem is that you can't really nest []'s
So maybe this:
Code:

if [-!e $4 ] || [ -e $4 ] && [ "$overwrite_flag" != 0 ]

Jay_Drummond 04-08-2008 09:51 PM

Code:

#!/bin/sh

overwrite_flag=1

if [ -e $4 ] && [ "$overwrite_flag" != 0 ] || [ ! -e $4 ]
then
  echo 'overwrite ok '$4
else
  echo 'no overwrite'
fi

I tested it, so I'm certain that this one works.


All times are GMT -5. The time now is 09:38 PM.