Welcome, Guest
Username Password: Remember me

Find command return type
(1 viewing) (1) Guest
Shell Script
  • Page:
  • 1

TOPIC: Find command return type

Find command return type 1 year, 4 months ago #528

  • scmuser
  • OFFLINE
  • Gold Boarder
  • scm master
  • Posts: 237
  • Points: 3429
  • Karma: 0
  • Honor Medal 2009
I am looking for following answer if anybody can help me out...

How to Return a message when a file is not found using find command? OR
Find command return type OR
when the file is not found i want it to return some value OR

Re: Find command return type 1 year, 4 months ago #533

  • tpatil
  • OFFLINE
  • Junior Boarder
  • Posts: 27
  • Points: 5106
  • Karma: 0
  • Honor Medal 2009
You can use exit code of find command to return the message.

e..g.
 
find . -name abc.txt > dev/null
 
if test $? -eq 0
then
echo "File found"
else
echo "File Not Found"
fi
 


Hope this helps...

Re: Find command return type 1 year, 4 months ago #534

  • rajeshkumar
  • OFFLINE
  • Moderator
  • I love software configuration management
  • Posts: 370
  • Points: 44589
  • Karma: 4
  • Honor Medal 2009
Hi..

I guess following script will not work. The problem here is find command does always return true value no matter if find is available or not.

this is unique things in find command.

I feel we should go ahead in this way.

find . -name raj.txt > raj.txt
counter= `cat abc.txt | wc -l'
 
if [$counter -gt 0]
then
echo "File is found"
else
echo "File is not found"
fi


please let us your inputs on this
Regards,
Rajesh Kumar
Build and Release Engineer
My Blog: community.scmgalaxy.com/pg/profile/rajeshkumar

Re: Find command return type 1 year, 4 months ago #536

  • tpatil
  • OFFLINE
  • Junior Boarder
  • Posts: 27
  • Points: 5106
  • Karma: 0
  • Honor Medal 2009
Thanks Rajesh...You are right. I tried with my code. Find always retuns 0 though file not found.
  • Page:
  • 1
Time to create page: 1.00 seconds

     
    
Home Forum