LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-08-2009, 05:09 PM   #1
sarturbest
LQ Newbie
 
Registered: Nov 2009
Posts: 2

Rep: Reputation: 0
Arrow exit status of command "find"


Hi all,
I am beginner in Linux.I want to do the following (bash shell):

if "find" command finds 'thereis' file in the current directory then "echo" Yes otherwise No.

Any ideas?

I tried to use exit status of "find" but it gives the same result in both cases.
 
Old 11-08-2009, 05:27 PM   #2
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,191

Rep: Reputation: 105Reputation: 105
Check the man page for find. The definition of the return status is rather broad, but it basically refers to all files having been processed successfully, not whether it found what you were looking for. There are other ways in the shell of asking whether a file exists or not.
 
Old 11-08-2009, 05:33 PM   #3
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 88
Yes, exit status won't do it here. A slightly messy indirect way would be to count the number of lines (matches) that find outputs:

Code:
if test `find . -name $filename | wc -l` -gt 0; then
   echo yes
else 
   echo no
fi
However, if it's just a simple file existence test that you're after, bash has built-in conditional operators to do this:

Code:
if [ -e $filename ]; then
   echo yes
else
   echo no
fi
There are several such operators (see man bash for more).
 
Old 11-09-2009, 03:52 AM   #4
sarturbest
LQ Newbie
 
Registered: Nov 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to exit and save (or just to exit) inside a "make config" running command? scrat75 Linux - Kernel 6 09-05-2008 05:02 PM
Compiling GIMP: "collect2: ld returned 1 exit status" linx win Debian 1 01-15-2007 01:08 AM
Help with "man pppd" exit status 10 Larry Webb Linux - Networking 1 07-29-2006 03:59 AM
kppp mdk10 ppp exit status 10 "CONNECT 44000/LAPM/" geek745 Linux - Networking 2 09-10-2004 12:04 AM
problem with "rpm -bb" , 1 out of 1 hunk ignored ...error: Bad exit status from /v wohaolouis Linux - Software 0 03-07-2004 08:12 AM


All times are GMT -5. The time now is 11:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration