RSS Forums RSS
Please support our Shell Scripting advertiser: Programming Forums
Views: 2337 | Replies: 6
Reply
Join Date: Jun 2005
Posts: 2
Reputation: schbrongx is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
schbrongx schbrongx is offline Offline
Newbie Poster

Solution Test with "[[ ... ]]" executing both, the && and the || clause

  #1  
Jun 2nd, 2005
Hi,

Maybe I should just make a break and go through this again by myself, but there is no more coffee, so there is no break for me

I want to check for a given dir, exit with a message if it exists, or create the given dir otherwise.

What happens is, that the shell executes the && Branch and wont exit afterwards but executes the || branch, too. Obviously mkdir throws an ugly error when the directory exists.

Dont get me wrong, I know how to make it work with the usual if construct, but I cant sleep well tonight, when I dont use a one-liner

[[ -d ${DIR_CUSTOMER} ]] && (echo "*** Information: Directory ${DIR_CUSTOMER} already exists!"; exit 1;) || (echo "*** Creating ${DIR_CUSTOMER}"; mkdir ${DIR_CUSTOMER};)


^^ do YOU see where I made a mistake?

hugs,
schbrongx
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: Test with "[[ ... ]]" executing both, the && and the || clause

  #2  
Jun 7th, 2005
what do the double brackets accomplish in the code above
[[ -d ${DIR_CUSTOMER} ]]
Reply With Quote  
Join Date: Jun 2005
Posts: 2
Reputation: schbrongx is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
schbrongx schbrongx is offline Offline
Newbie Poster

Re: Test with "[[ ... ]]" executing both, the && and the || clause

  #3  
Jun 7th, 2005
the brackets initiate a test.

[[ -d DIRECTORY ]] tests for the existence of a directory
[[ -e FILE ]] tests if a file exists
etc. etc.

[[ $VAR -gt 5 ]] tests, if $VAR' s content is greater then 5, etc. etc.
Reply With Quote  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: Test with "[[ ... ]]" executing both, the && and the || clause

  #4  
Jun 7th, 2005
can't that be accomplished with a single set of brackets, are the double set nessesary?
Reply With Quote  
Join Date: Nov 2004
Posts: 21
Reputation: vgersh99 is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
vgersh99's Avatar
vgersh99 vgersh99 is offline Offline
Newbie Poster

Re: Test with "[[ ... ]]" executing both, the && and the || clause

  #5  
Jun 7th, 2005
Originally Posted by shanenin
can't that be accomplished with a single set of brackets, are the double set nessesary?

Look at this: [[ vs ]
vlad
+-----------------------------------+
| #include <disclaimer.h> |
+-----------------------------------+
Reply With Quote  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: Test with "[[ ... ]]" executing both, the && and the || clause

  #6  
Jun 8th, 2005
Thanks fot the nice link, that clears it up :-)
Reply With Quote  
Join Date: Jun 2005
Posts: 1
Reputation: beltagui is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
beltagui beltagui is offline Offline
Newbie Poster

Re: Test with "[[ ... ]]" executing both, the && and the || clause

  #7  
Jun 12th, 2005
hey there I'm just registered today, if it's not late I do have the soultion for ur Q

[[ -d ${DIR_CUSTOMER} ]]
&& (echo "*** Information: Directory ${DIR_CUSTOMER} already exists!"; exit 0
|| (echo "*** Creating ${DIR_CUSTOMER}"; mkdir ${DIR_CUSTOMER}
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:47 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC