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

[[ -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

what do the double brackets accomplish in the code above

[[ -d ${DIR_CUSTOMER} ]]

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.

can't that be accomplished with a single set of brackets, are the double set nessesary?

can't that be accomplished with a single set of brackets, are the double set nessesary?

Look at this: [[ vs ]

Thanks fot the nice link, that clears it up :-)

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};)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.