Sponsored Content
Full Discussion: check the directory exist
Top Forums Shell Programming and Scripting check the directory exist Post 77097 by mbb on Monday 4th of July 2005 09:59:17 AM
Old 07-04-2005
FYI ust:

if [ -d $dir ]
then
...
fi

is actually using the 'test' command. To find out what you can do with the test command then type: 'man test'

You may also write the above as:

if test -d $dir
then
...
fi

or even use the test command on the comand line thus:

>test -d $dir
>echo $?

Also I would recommend shell variables to be quoted in this context:

if [ -d "$dir" ] ...

to avoid any command line errors with the test command!

i.e. if $dir were emtpy and you did if [ -d $dir ], then you would really be running: 'test -d' and the test command would complain.

Hope this helps.

MBB
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to check if the file exist or not?

say i would like to check if the file is existed before i use rm command. How can i do it? i know if i can use find, but i would like to have a good interface (in a shell script) thks (3 Replies)
Discussion started by: gusla
3 Replies

2. Shell Programming and Scripting

how to check if directory/file exist using c/c++

Hi there,, how to check if directory/file exist using c/c++ under unix/linux? I can use access() under Window MFC. Thanks. Steven (1 Reply)
Discussion started by: steven88
1 Replies

3. Programming

how to check if directory/file exist using c/c++

Hi there, how to check if directory/file exist using c/c++ under linux/unix. Thanks. Steven (2 Replies)
Discussion started by: steven88
2 Replies

4. Shell Programming and Scripting

Check if certain files exist in a directory, if not add name to a textfile

We recieve some logs on our windows box via FTP on a daily basis, in the same directory. I would like to check for missing logs files and add their name to a text file. Something like... Check if C:\logs\file1_currentdate exists (if not, add file1_currentdate to... (1 Reply)
Discussion started by: SunnyK
1 Replies

5. Shell Programming and Scripting

How to check directory exist on servers

There are many servers and their directory structer should be exactly the same. To check the directory path for all servers, I wrote a script. #! /bin/ksh ARRAY_DIRECTORIES="/c/dev/custom/bin" ARRAY_DIRECTORIES="/c/dev/db/custom/src" ARRAY_ENV="remoteName200" ARRAY_ENV="remoteName201"... (2 Replies)
Discussion started by: weonpc
2 Replies

6. Shell Programming and Scripting

To check whether a directory is exist and if it is not, create it

Hi, I want to write a shell script to check whether a directory (say A) is existing in a given location and if it is not, create it. (3 Replies)
Discussion started by: sabya
3 Replies

7. Shell Programming and Scripting

Check if file exist

Hi Does anybody know how I can check if a file exists i.e. see bellow, this doesn't work by the way and if tried countless variations on this file1=$one/file111.txt if then echo "Present" else echo "Not present" fi result : Not present (file is already present, eventhough its... (3 Replies)
Discussion started by: gksenthilkumar
3 Replies

8. Shell Programming and Scripting

Check if file exist

Hi, I am trying to create a bash script which will check if file exist then remove that file else do nothing. I have to do same process for three files in same script. I have written code for one file and trying to run it. if then rm -r /user1/abc/File1 fi When I run this code it... (1 Reply)
Discussion started by: palak08
1 Replies

9. Shell Programming and Scripting

Check if file exist

Hi, I created following script to check if file exist: #!/bin/bash SrcDir=$1 SrcFileName=$2 SrcTimePeriod=$3 if ;then echo 1 else echo 0 fi I ran it like: /apps/Scripts/FileExist.sh /apps/Inbox file1 2nd_period_2010 Even file exist at that location, my above command is... (4 Replies)
Discussion started by: palak08
4 Replies

10. Shell Programming and Scripting

how to check file exist in a directory or not

HI folks, can any one tell me how to check whether the file is existed in a directory or not . let me tell you my requirement : if the file is existed i should display a one message or else i have to send a mail .. i have the mail logic .. but I'm failed to check file existence .. please... (5 Replies)
Discussion started by: sravan008
5 Replies
Test::InDistDir(3pm)					User Contributed Perl Documentation				      Test::InDistDir(3pm)

NAME
Test::InDistDir - test environment setup for development with IDE VERSION
version 1.112071 SYNOPSIS
use Test::More; use Test::InDistDir; # when this is run from inside t/ with a default @INC, it will now be in the # dist dir and include ./lib in @INC DESCRIPTION
This module helps run test scripts in IDEs like Komodo. When running test scripts in an IDE i have to set up a project file defining the dist dir to run tests in and a lib dir to load additional modules from. Often I didn't feel like doing that, especially when i only wanted to do a small patch to a dist. In those cases i added a BEGIN block to mangle the environment for me. This module basically is that BEGIN block. It automatically moves up one directory when it cannot see the test script in "t/$scriptname" and includes 'lib' in @INC when there's no blib present. That way the test ends up with almost the same environment it'd get from EUMM/prove/etc., even when it's actually run inside the t/ directory. At the same time it will still function correctly when called by EUMM/prove/etc., since it does not change the environment in those cases. SUPPORT
Bugs / Feature Requests Please report any bugs or feature requests by email to "bug-test-indistdir at rt.cpan.org", or through the web interface at http://rt.cpan.org/Public/Dist/Display.html?Name=Test-InDistDir <http://rt.cpan.org/Public/Dist/Display.html?Name=Test-InDistDir>. You will be automatically notified of any progress on the request by the system. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. https://github.com/wchristian/Test-InDistDir <https://github.com/wchristian/Test-InDistDir> git clone https://github.com/wchristian/Test-InDistDir AUTHOR
Christian Walde <walde.christian@googlemail.com> COPYRIGHT AND LICENSE
This software is Copyright (c) 2011 by Christian Walde. This is free software, licensed under: DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE, Version 2, December 2004 perl v5.12.4 2011-07-26 Test::InDistDir(3pm)
All times are GMT -4. The time now is 06:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy