LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-09-2009, 01:57 PM   #1
gqchynaboy
LQ Newbie
 
Registered: Jul 2003
Posts: 20

Rep: Reputation: 0
If directory doesn't exist, try the next one? - Which command to use?


I have a little script where it goes to a certain directory, but if that directory doesn't exist, I want to try to go to a different directory. What linux commands should I be using?

For example:

#Go to this directory
cd $HOME/Desktop/"${projName}"/HTML

if = FAILS
{ go to this directory}



Thanks
 
Old 12-09-2009, 02:35 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
In case of failure, is it always the same other directory you want
to go to, or just the next one in a list?
 
Old 12-09-2009, 02:51 PM   #3
MBybee
Member
 
Registered: Jan 2009
Location: wherever I can make a living
Distribution: OpenBSD / Debian / Ubuntu / Win7 / OpenVMS
Posts: 440

Rep: Reputation: 57
You can do something like -d: http://stackoverflow.com/questions/5...h-shell-script

Example
Code:
if [ -d "$DIR" ]; then 
   #do whatever
else
   #do something else
fi
 
Old 12-09-2009, 06:24 PM   #4
gqchynaboy
LQ Newbie
 
Registered: Jul 2003
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by MBybee View Post
You can do something like -d: http://stackoverflow.com/questions/5...h-shell-script

Example
Code:
if [ -d "$DIR" ]; then 
   #do whatever
else
   #do something else
fi

That worked perfectly, thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Home directory does not exist emibee Linux - Laptop and Netbook 8 03-17-2009 04:20 PM
check if directory exist jaepi Programming 6 05-10-2007 09:45 PM
Home Directory Does not exist PLEASE HELP scdemon Ubuntu 2 02-10-2007 05:32 PM
report that such directory doesn't exist hpaixao Programming 3 02-20-2005 11:30 AM
apache directory does not exist Smokey Slackware 5 08-25-2004 09:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration