Please support our Shell Scripting advertiser: Programming Forums
Views: 2337 | Replies: 6
![]() |
•
•
Join Date: Jun 2005
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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
^^ do YOU see where I made a mistake?
hugs,
schbrongx
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
•
•
Join Date: May 2005
Posts: 215
Reputation:
Rep Power: 4
Solved Threads: 0
what do the double brackets accomplish in the code above
[[ -d ${DIR_CUSTOMER} ]]•
•
•
•
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> |
+-----------------------------------+
+-----------------------------------+
| #include <disclaimer.h> |
+-----------------------------------+
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)





Linear Mode