Searching directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching directory
# 1  
Old 05-18-2009
Searching directory

The command is to search all the matched directory under $HOME, the input i directory is the last argument
it works perfectly by itself
but after a method call, it wont work cant figure out why

Code:
dirNameCheck(){
 for i in $*
 do
   test $1
 done
 noMatch=`find HOME -type d -name $i | wc -l`
 if [ $noMatch -eq 0 ]
 then 
   echo " there is no such directory "
   dir=`pwd`
 else
   dir=$i
 fi
}

if [ $# -lt 1 ]
then 
  echo "Useage : blablabla "
else
  dirNameCheck;
fi

for command
i wrote
Code:
sh fileName -name dirName

it displayed as miss argument to -name
no such directory
even there is a directory same as the argument
it still display "there is no such directory"

thank you for helping

Last edited by otheus; 05-25-2009 at 07:40 AM.. Reason: indentation
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Searching the file in a directory

Hi Folks, I am using the putty as I need to check the logs, My query is that I know the location of my logs ..that is cd /var /logs/abc.log so I can reach to this place and open the logs in putty, But what About if I do not the location only thing I know the name of the abc.log , and I have... (1 Reply)
Discussion started by: KAREENA18
1 Replies

2. Shell Programming and Scripting

Copy file after searching in a directory

Hi, I am looking for an answer for following senario: I have a text file (base.txt) which consist list of files to be searched like: base.txt abc.txt def.txt fgh.txt Now i am going to search all the listed files in another directory after reading them one by one, once i found the... (10 Replies)
Discussion started by: apjneeraj
10 Replies

3. Solaris

Searching for files in a Directory

Hi, I am trying to write a script that will search in a particular directory and tell me how many files are in there. I then want to be able to email certain users of how many files are in that directory and what the file names are? any help would be great as i am getting confused. thanks (3 Replies)
Discussion started by: Pablo_beezo
3 Replies

4. Shell Programming and Scripting

Searching directory tree

I'm currently trying to write a script that will do the following: search a given directory tree for a file with MMDDYYYY in the name. delete those files only. I can't figure out how to make the script delete the files with the MMDDYYYY in the filename after finding them. Should I export... (7 Replies)
Discussion started by: blane
7 Replies

5. Shell Programming and Scripting

searching each file in a directory for text

what command can i use to search the files in a directory for a text. the output would list the files containing the text. ive tried this but it is not exactly what im looking to do: find . -name "*.xml" -exec agrep searchstring {} \; (2 Replies)
Discussion started by: jim majors
2 Replies

6. Shell Programming and Scripting

Searching files in a directory.Urgent

Hi everyone, I need to search files starting with RPT_0, RPT_1,........ in a directory. How can I implement that through a shell script. Also I want to read the last line of each file after searching them. Can someone help me out in this regard. One more thing how I can extract a particular... (7 Replies)
Discussion started by: srivsn
7 Replies

7. Shell Programming and Scripting

Searching for directory

Hi, I am new to Unix and am using csh to create a script where all files in a directory of a particular type are changed. As an example, if rename.csh tmp .tab .txt is entered at the command line, all of the .tab files in the tmp directory will be changed to .txt files. I have created the... (8 Replies)
Discussion started by: Enigma23
8 Replies

8. Filesystems, Disks and Memory

Searching for a pattern in a Directory

How to search a given pattern in the files which are present in my current working directory and its subdirectories recursively (1 Reply)
Discussion started by: gandhevinod
1 Replies

9. Shell Programming and Scripting

directory searching

i have a set of directories, all with a set of files inside ie name/week1 there is a selection of files in each directory, and i need to read each one, and find data in each one, although not all the numbers are there can anyone help me please (i know this is kinda vague, just pm... (2 Replies)
Discussion started by: st00pid_llama
2 Replies

10. UNIX for Dummies Questions & Answers

searching for a string in directory

Hi, I have a directory with a couple of thousand logs in it. The log files are created every 5 minutes. I want to search these logs grep for a specific sting and more importantly print the name of the files where that sting was found. e.g. all logs begin om20020927 what I have been... (4 Replies)
Discussion started by: warrend
4 Replies
Login or Register to Ask a Question