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

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?

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

This article has been dead for over six months. Start a new discussion instead.