Sponsored Content
Full Discussion: Directory exists
Top Forums UNIX for Dummies Questions & Answers Directory exists Post 302084478 by nathan on Friday 11th of August 2006 07:28:05 AM
Old 08-11-2006
From the manual for 'test':
Code:
[(1)                             User Commands                            [(1)

NAME
       test - check file types and compare values

SYNOPSIS
       test EXPRESSION
       [ EXPRESSION ]
       [ OPTION

       -d FILE
              FILE exists and is a directory

       -e FILE
              FILE exists

So,
Code:
MY_DIR="ZZZ"
if [ ! -d $MY_DIR ] ; then
  mkdir $MY_DIR
fi

Of course this will still fail if MY_DIR exists but is something other than a directory. So to prevent that you would use the -e option instead of -d.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

check if directory exists

Hi, I need to prompt for a response from a user to enter a path read dest_dir?"Please Enter Directory :" How do I do this until a valid directory is entered by the user. I can use to check the existence of the directory. However when I try the following I cannot get it to work. while ... (2 Replies)
Discussion started by: jerardfjay
2 Replies

2. Shell Programming and Scripting

how to check if masked directory exists?

I'm trying to write a script that identifies whether a directory of the form AWL.????????.IP exists. I have one that exists which is AWL.05301032.IP. When I test like this: If ] I get true, but when I test like this: If ] Or like this If ] Or any other variation of wild cards, I... (4 Replies)
Discussion started by: philplasma
4 Replies

3. UNIX for Dummies Questions & Answers

How can I check if directory exists in a makefile

Hi. I what to write a make file that inside a target I want to check if a directory exists. some like: ### make a: if ;then <command 1> else <command 2> fi ### make end Thanks a lot ---------------------- (2 Replies)
Discussion started by: zivsegal
2 Replies

4. Shell Programming and Scripting

Problem when test to see if directory exists

Hi, I'm writing a shell script that will create a folder if it does not exist yet. Here's the script: (this if statement is inside a while loop) folderName="Pics" if ! test -d folderName then mkdir $folderName fi However, after the folder Pics has been created, every time the... (3 Replies)
Discussion started by: trivektor
3 Replies

5. Shell Programming and Scripting

my scripts does not check if directory exists

Hello: Can someone please help me figure out what is wrong here, my script does not move on to the "else" part even though there is no .ssh directory on my remote server: $more putkey.sh #!/bin/ksh for server in `cat list` do if ; then cat $HOME/.ssh/id_rsa.pub |ssh $server ' cat >>... (4 Replies)
Discussion started by: Sara-sh
4 Replies

6. Shell Programming and Scripting

check if a directory exists if not make it

Hey guys im trying to check if the directory exists i get a syntax error on the elif statement iv tried using else and still same result im not sure. If the directory does not exist can i just insert mkdir /tmp/old under the elif once that part gets working if ; then #do nothing elif echo... (20 Replies)
Discussion started by: musicmancanora
20 Replies

7. Shell Programming and Scripting

perl, if directory exists

Hi there I am trying to make a fuction that looks for a email profile that ends in .$ARGV here is the code if (-d "/Users/$ARGV/Library/Thunderbird/Profiles/*.$ARGV") { print "\n WARNING: Email profile already exits\n\n"; exit; } but for some reason it does... (2 Replies)
Discussion started by: ab52
2 Replies

8. Shell Programming and Scripting

how to check if a directory exists or not.if not need to create it

Hi, I am using solaris 10 OS and bash shell.just checking for small code snippet which follows below. /export/home/vomappservers/spa/common/5.0 /export/home/vomappservers/spa/common/scripts /export/home/vomappservers/spa/tools /export/home/vomappservers/spa/scm5.0/SCCS... (5 Replies)
Discussion started by: muraliinfy04
5 Replies

9. Shell Programming and Scripting

script to tell whether there exists directory or not

Hi, I am writing a script as follows: #!/bin/sh set -x for i in `cat a`; do #sleep 3 print $i >> server.txt sleep 5 if test -d `vtask $i "' ls -lrt /opt/log/ '" ` ; then print $i >> 12.5.txt else print $i >> 12.0.txt fi done (7 Replies)
Discussion started by: dbashyam
7 Replies

10. Shell Programming and Scripting

How to check if the file exists in directory?

Hi Gurus, I have a requests to find if all the file in the filelist exist in certain directory. example: my filelist abc def ddd cde afg how can I find these 5 files exists at director /home/abc Thanks in advance (7 Replies)
Discussion started by: ken6503
7 Replies
CUBRID_IS_INSTANCE(3)							 1						     CUBRID_IS_INSTANCE(3)

cubrid_is_instance - Check whether the instance pointed by OID exists

SYNOPSIS
int cubrid_is_instance (resource $conn_identifier, string $oid) DESCRIPTION
The cubrid_is_instance(3) function is used to check whether the instance pointed by the given $oid exists or not. PARAMETERS
o $conn_identifier -Connection identifier. o $oid -OID of the instance that you want to check the existence. RETURN VALUES
1, if such instance exists; 0, if such instance does not exist; -1, in case of error EXAMPLES
Example #1 cubrid_is_instance(3) example <?php $conn = cubrid_connect("localhost", 33000, "demodb"); $sql = <<<EOD SELECT host_year, medal, game_date FROM game WHERE athlete_code IN (SELECT code FROM athlete WHERE name='Thorpe Ian'); EOD; $req = cubrid_execute($conn, $sql, CUBRID_INCLUDE_OID); $oid = cubrid_current_oid($req); $res = cubrid_is_instance ($conn, $oid); if ($res == 1) { echo "Instance pointed by $oid exists. "; } else if ($res == 0){ echo "Instance pointed by $oid doesn't exist. "; } else { echo "error "; } cubrid_disconnect($conn); ?> The above example will output: Instance pointed by @0|0|0 doesn't exist. SEE ALSO
cubrid_drop(3), cubrid_get_class_name(3). PHP Documentation Group CUBRID_IS_INSTANCE(3)
All times are GMT -4. The time now is 11:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy