LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   If directory doesn't exist, try the next one? - Which command to use? (https://www.linuxquestions.org/questions/linux-newbie-8/if-directory-doesnt-exist-try-the-next-one-which-command-to-use-774530/)

gqchynaboy 12-09-2009 12:57 PM

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

Tinkster 12-09-2009 01:35 PM

In case of failure, is it always the same other directory you want
to go to, or just the next one in a list?

MBybee 12-09-2009 01:51 PM

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


gqchynaboy 12-09-2009 05:24 PM

Quote:

Originally Posted by MBybee (Post 3785783)
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!


All times are GMT -5. The time now is 02:41 PM.