LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux > Linux - Newbie
User Name
Password
Linux - Newbie This 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
 
Thread Tools
Old 11-08-2009, 05:09 PM   #1
sarturbest
LQ Newbie
 
Registered: Nov 2009
Posts: 2
Thanked: 0
Arrow exit status of command "find"


[Log in to get rid of this advertisement]
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.
windows_xp_2003 sarturbest is offline     Reply With Quote
Old 11-08-2009, 05:27 PM   #2
choogendyk
Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 852
Thanked: 34
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.
macos choogendyk is offline     Reply With Quote
Old 11-08-2009, 05:33 PM   #3
Robhogg
Member
 
Registered: Sep 2004
Location: solihull.w-mids.uk
Distribution: Debian 5.0, CentOs
Posts: 499
Thanked: 41
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).
linuxdebian Robhogg is offline     Reply With Quote
Old 11-09-2009, 03:52 AM   #4
sarturbest
LQ Newbie
 
Registered: Nov 2009
Posts: 2
Thanked: 0

Original Poster
Thanks
windows_xp_2003 sarturbest is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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 05:15 AM.

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration