How to search for a directory with if clause?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to search for a directory with if clause?
# 1  
Old 10-31-2013
How to search for a directory with if clause?

Hello All,

I want to do a conditional search for a directory, i.e

pathname=/abc/def
foldername=xyz
if ( $pathname/$foldername/aaa )
then
..................
fi

Here i am searching for aaa directory inside the path and if it exist then it should go inside the loop.

Can anybody help me on this.

Thanks in advance.
# 2  
Old 10-31-2013
Code:
pathname=/abc/def
foldername=xyz
if [ -d ${pathname}/${foldername}/aaa ]
then
	echo "dir exists"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

To do directory tree search

Hello Everyone, I need to find the file / directory with the maximum timestamp in a directory tree having many files / directories. Could you please help. Thanks, H squared (3 Replies)
Discussion started by: H squared
3 Replies

2. Shell Programming and Scripting

Change to directory and search some file in that directory in single command

I am trying to do the following task : export ENV=aaa export ENV_PATH=$(cd /apps | ls | grep $ENV) However, it's not working. What's the way to change to directory and search some file in that directory in single command Please help. (2 Replies)
Discussion started by: saurau
2 Replies

3. Shell Programming and Scripting

Directory Search Perl

@scriptfiles=glob('*.txt'); foreach $file (glob('*.txt')) { open(my $fh, $file) or die("Unable to open '$file': $!"); while (my $line = <$fh>) { if ($line =~ m/(Apple|Orange|Guava)/i) { $Sheet->Cells($row,$col-1)->{'Value'} = $file; ... (1 Reply)
Discussion started by: rajkrishna89
1 Replies

4. UNIX for Dummies Questions & Answers

search for a pattern in a directory?

Hi, i need help on how to do this: to make a shell script that reads 2 parameters in command line, one directory and pattern. Then it must search for the string in all files starting from the indicated directory (including subfolders) and excluding binary files. The results should show the... (1 Reply)
Discussion started by: ubu-user
1 Replies

5. UNIX for Dummies Questions & Answers

File search in the directory

Hi! All, I am new here... Hello to all!!!!!!!! I want to know how to know files present in the directory. i do not want direcory name in the directory? (5 Replies)
Discussion started by: kaushelsh168
5 Replies

6. Shell Programming and Scripting

How to search a directory in unix

Hi, I'm very new to shell script. Try to search a directory named construction using : find construction -type d. but don't know the path. so it can not stat. want to return the path of directory construction. can anyone help me. (4 Replies)
Discussion started by: samir_standing
4 Replies

7. Shell Programming and Scripting

Reg: Search for a directory

Dear All, I am new to Unix and i need a small Help from you Guys..... The current structure of my system is as follows: /Abc/xyz/cpd/std/re/doc Each cpd directory has n number of std's. Each std has n number of re's. My requirement is to write a UNIX script that would search whether doc... (8 Replies)
Discussion started by: Rajanikanth
8 Replies

8. UNIX for Advanced & Expert Users

Reg: Search for a directory

Dear All, I am new to Unix and i need a small Help from you Guys..... The current structure of my system is as follows: /Abc/xyz/cpd/std/re/doc Each cpd directory has n number of std's. Each std has n number of re's. My requirement is to write a UNIX script that would search... (0 Replies)
Discussion started by: Rajanikanth
0 Replies

9. Shell Programming and Scripting

search all files and sub directory

I wanted to search in all the sub directories under /vob/project (recurse) in everything inside /vob/project. search.run for x in `cat search.strings` do find /vob/project -type f -print | xargs grep -i $x > ~/$x.txt done search.string hello whoami I am getting the error ... (5 Replies)
Discussion started by: siva_jm
5 Replies

10. Programming

Directory tree search???

Hi all, I've got a problem, what function do i use to list the contents of all the directory tree (simular to "find")? Any other suggestions? Thank you all (3 Replies)
Discussion started by: solvman
3 Replies
Login or Register to Ask a Question