Register
It is currently Fri Jul 25, 2014 5:18 am

Problem with find


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Tue Oct 23, 2012 12:49 pm   

Joined: Tue Oct 23, 2012 12:45 pm
Posts: 1
I'm a newbie, I want to write a simple shell code to find a file, and if it exist vi it. But I have some problem with find command
this is the part i have problem.
Quote:
read -p "Input a name of file:" name
`find / -name $name>searchresult.txt`
$c=`head -n 1 searchresult.txt`

and the result of this code is
Quote:
=/My file location: No such of file or directory

please help me.;)


Top
 Profile  
 PostPosted: Tue Oct 23, 2012 3:44 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 532
hi,

you problem does not come from find, but from variable assignment : it doesn't use a dollar sign.
dollar sign is for expanding the variables:
Code:
var="foo"
echo "$var"

if your `find` is GNU or BSD, it has a '-quit' option so it stops processing path(s) as soon as it finds a match.
Code:
find $path -iname "$shellPattern" -exec vi {} \; -quit


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP