LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find exactly in that directory (http://www.linuxquestions.org/questions/linux-newbie-8/find-exactly-in-that-directory-475875/)

basak 08-21-2006 08:08 AM

find exactly in that directory
 
hi:)
I want to use smth . like

if [ -e file ] ;then
-----
fi

statement but I want to know if that file exists under just some given directory(not including its subdirectories) instead of the current directory.I tried

var1=$(find givendirectory -name file)
if [ $var1 != "" ] ;then
---
fi

but of course that did not work because

1) find givendirectory -name file command does not search in only the given directory,it also looks in the subdirectories of it.
2) $var1 is never "" because if the file does not exits , the command does not substitude ""
to var1 ,it substitudes "find: he: No such file or directory"

is there a practical way to search under a given directory for whether a file exists?

Nathanael 08-21-2006 08:26 AM

pass given directory as param1 and filename to param2
e.g.
./blah.sh dir file

Code:

#!/bin/bash

DIR=$1
FILE=$2

if [ -f "${DIR}/${FILE}" ] ; then
echo "$FILE exists in $DIR"
else
echo "$FILE does not exist in $DIR"
fi
exit



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