LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Testing for a folder (https://www.linuxquestions.org/questions/linux-newbie-8/testing-for-a-folder-533806/)

Ian D 03-02-2007 01:55 AM

Testing for a folder
 
I want to write a BASH script which can detect if a folder exists on the disk.

What command do I use?

Thanks for your help.

Ian

acid_kewpie 03-02-2007 02:29 AM

if [ -d /where/ever ]
...
fi

Ian D 03-02-2007 10:49 AM

Thanks, That gets me going.

Actually, I need to mkdir if the folder does not exist (which I realize is not what I asked for) and I find that I have to say
if [ -d $folder ]; then
nothing=1
else
mkdir $folder
fi

I know that you will be able to tell me a more elegant way to do this than having a dummy assignment statement.

Ian
:newbie:

acid_kewpie 03-02-2007 11:59 AM

[ -d /where/ever ] || mkdir /where/ever

tuxrules 03-02-2007 12:17 PM

A slightly concise solution...

Code:

if [ ! -d /what/ever] ; then
mkdir /what/ever
fi


acid_kewpie 03-02-2007 02:23 PM

mine's conciserer. i could say [ ! -d /where/ever ] && mkdir /where/ever but that uses two more characters!

Ian D 03-02-2007 03:06 PM

Great!

Elegant!

Works!


All times are GMT -5. The time now is 05:03 PM.