User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 397,689 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,548 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser:
Views: 32779 | Replies: 7 | Solved
Reply
Join Date: Dec 2004
Posts: 8
Reputation: iparkin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
iparkin iparkin is offline Offline
Newbie Poster

Help Using find in a bash shell script

  #1  
Dec 2nd, 2004
I recently ran the following command from the command line and it worked
find . -name '*jrAPS*_ouput.log' -exec grep '<string expression>' {}\; -print

I put it in a shell script like this and it did not work
find . -name \'*jrAPS*_output.log\' -exec grep \'<string expression>\' {} \\\; -print

the result was find: incomplete statement why?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Posts: 2
Reputation: coca-light is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
coca-light coca-light is offline Offline
Newbie Poster

Re: Using find in a bash shell script

  #2  
Dec 2nd, 2004
On my system, I don't need to perform all the escaping that you are doing. The same command that I use on the command line works in the shell script because nothing is interpreting the command before executing it. However, if you have another shell reading commands from this script and executing them, then you would need the escapes. If that doesn't help use bash -n $0 where $0 is your current command line to see if you have syntax errors before running. Sometimes the error messages are slightly different (or more of them) when just analyzing.
Reply With Quote  
Join Date: Dec 2004
Posts: 8
Reputation: iparkin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
iparkin iparkin is offline Offline
Newbie Poster

Solution Re: Using find in a bash shell script

  #3  
Dec 3rd, 2004
Thanks I will do that do you know any Linux servers I can get access to on the net to try this.?
Reply With Quote  
Join Date: Dec 2004
Posts: 2
Reputation: coca-light is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
coca-light coca-light is offline Offline
Newbie Poster

Re: Using find in a bash shell script

  #4  
Dec 3rd, 2004
Sorry, I don't know of any public Linux Servers.
If you need an easy install try Xandros Open Edition. You answer 5 or 10 questions, wait about 30 minutes and voila instant Linux - with sound and networking. http://www.xandros.com
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,881
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 108
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Using find in a bash shell script

  #5  
Dec 3rd, 2004
Reply With Quote  
Join Date: Dec 2004
Posts: 8
Reputation: iparkin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
iparkin iparkin is offline Offline
Newbie Poster

Re: Using find in a bash shell script

  #6  
Dec 4th, 2004
Thanks I will check out these sites
Reply With Quote  
Join Date: Dec 2004
Posts: 8
Reputation: iparkin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
iparkin iparkin is offline Offline
Newbie Poster

Re: Using find in a bash shell script

  #7  
Dec 5th, 2004
Here is the shell script I am trying to run in bash

if [ $# -neq 1 ];
then
echo "Usage: <program name> <string expression>"
exit 1
fi

findstr=$1
echo "$findstr"

find . -name 'm1_jrAPS*_output.log' -exec grep \'"$findstr"\' {} \; -print


In the above script I want to take the string from the command line and put it in the find command in the shell script I have a hard time getting the shell to expand it in single quotes like in the regular command
Reply With Quote  
Join Date: Dec 2004
Posts: 8
Reputation: iparkin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
iparkin iparkin is offline Offline
Newbie Poster

Re: Using find in a bash shell script

  #8  
Dec 19th, 2004
I found an easier solution using command substitution and looping.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Shell Scripting Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 1:00 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC