LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-08-2008, 09:25 PM   #1
jim.thornton
Member
 
Registered: May 2007
Posts: 404

Rep: Reputation: 19
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?
 
Old 04-08-2008, 09:41 PM   #2
PatrickNew
Senior Member
 
Registered: Jan 2006
Location: Charleston, SC, USA
Distribution: Debian, Gentoo, Ubuntu, RHEL
Posts: 1,148
Blog Entries: 1

Rep: Reputation: 48
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 ]
 
Old 04-08-2008, 09:51 PM   #3
Jay_Drummond
Member
 
Registered: Jul 2005
Location: Ohio
Distribution: CentOS 4 & 5, Ubuntu 7.04 & 7.10
Posts: 38

Rep: Reputation: 15
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.

Last edited by Jay_Drummond; 04-08-2008 at 09:55 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
New to shell scripting. Need help with conditions koobi Programming 12 11-09-2007 07:28 AM
question about C++ syntax bx.s Programming 3 07-27-2006 07:50 PM
C++ syntax question jiml8 Programming 6 06-20-2006 04:19 PM
Syntax question satimis Linux - Newbie 9 09-23-2004 07:47 AM
expect scripting syntax problems...(catch, echo,....) wedgeworth Linux - Software 2 10-02-2003 09:24 AM


All times are GMT -5. The time now is 04:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration