Go Back   Technology Questions > Software Questions > Operating System Questions > Linux

Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old 06-30-2008, 10:11 AM
Aaron Gray
Tablet PC Guest
 
Posts: n/a
Quick bash question

I need to create a directory if one does not exist.

if [ -d test]; then mkdir test; fi

does the opposite, how do it ?

I have tried :-

if [! -d test]; then mkdir test; fi

but that does not work.

Aaron


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

 
Old 06-30-2008, 10:11 AM
Xploder HD Movie Player for PS3. Manage, convert and transfer media files between the PC and PS3.
  #2 (permalink)  
Old 06-30-2008, 10:51 AM
Lew Pitcher
Tablet PC Guest
 
Posts: n/a
Re: Quick bash question

In alt.os.linux, Aaron Gray wrote:

> I need to create a directory if one does not exist.
>
> if [ -d test]; then mkdir test; fi
>
> does the opposite, how do it ?
>
> I have tried :-
>
> if [! -d test]; then mkdir test; fi
>
> but that does not work.


It would, with proper formatting

Try
if [ ! -d test ] ; then mkdir test ; fi
or
[ ! -d test ] && mkdir test
or
[ -d test ] || mkdir test



--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #3 (permalink)  
Old 06-30-2008, 10:51 AM
Aaron Gray
Tablet PC Guest
 
Posts: n/a
Re: Quick bash question

"Lew Pitcher" <lpitcher@teksavvy.com> wrote in message
news:70069$486922c5$cef8b59e$24609@TEKSAVVY.COM-Free...
> In alt.os.linux, Aaron Gray wrote:
>
>> I need to create a directory if one does not exist.
>>
>> if [ -d test]; then mkdir test; fi
>>
>> does the opposite, how do it ?
>>
>> I have tried :-
>>
>> if [! -d test]; then mkdir test; fi
>>
>> but that does not work.

>
> It would, with proper formatting
>
> Try
> if [ ! -d test ] ; then mkdir test ; fi
> or
> [ ! -d test ] && mkdir test
> or
> [ -d test ] || mkdir test


Great, thanks Lew.

Aaron


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #4 (permalink)  
Old 06-30-2008, 12:00 PM
Ben Collver
Tablet PC Guest
 
Posts: n/a
Re: Quick bash question

I have seen many a Makefile that just uses the -p flag. For example:

mkdir -p test

This will succeed even if the directory already exists.

Cheers,

Ben
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #5 (permalink)  
Old 06-30-2008, 12:30 PM
Aaron Gray
Tablet PC Guest
 
Posts: n/a
Re: Quick bash question

"Ben Collver" <BenCollver******.com> wrote in message
news:f1f7ff6d-0833-4275-996d-54be4fa61e29@r37g2000prm.googlegroups.com...
>I have seen many a Makefile that just uses the -p flag. For example:
>
> mkdir -p test
>
> This will succeed even if the directory already exists.


Right, thanks,

Aaron


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash question Eric Linux 5 02-08-2008 01:30 AM
Quick question. Red2Blue Windows Vista 1 10-22-2007 06:20 PM
cron.daily bash scripting question Beowulf Linux 2 01-15-2007 12:02 PM
Re: Quick question Chris H. Microsoft OneNote 0 01-07-2007 12:15 AM
A quick question for someone niknik1971 Windows Vista 1 01-01-2007 09:35 PM


All times are GMT -8. The time now is 02:50 PM.


2003 - 2008 All Rights Reserved. Technology Questions

SEO by vBSEO 3.1.0