LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-05-2011, 12:57 PM   #1
ghadley_00
LQ Newbie
 
Registered: Sep 2011
Posts: 1

Rep: Reputation: Disabled
Problem running bash script recursively over a number of subdirectories using osx


Hi,

I have a bash script (pt2.sh) that I would like to run on a number of directories. The directories are structured as follows:

Test1, within which there are 3 subdirectories which actually containg the files on which I wish to run the script (test1a, test1b, test1c). A .gz file is within each subdirectory (and is the target of the script), though the script will need to create additional files and then use those files before moving on. The script is designed to only work on the .gz file and the subsequence created files within the same directory.

I have been trying to run a script that
find . \*.gz -mindepth 2 -exec ./pt2.sh '{}' \;

but I keep getting errors stating the files that the scripts creates cannot be found.

Any suggestions would be greatly appreciated.

Best wishes,

GH
 
Old 09-05-2011, 07:33 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I would be guessing (Seeing as you have given no indication to actual code) that your script is referencing locally
so is actually creating the files in the executed directory instead of the found one.

Choices are to change into the directory found using find or have your script break down the location of
the .gz file and prepend it to the files created.
 
Old 09-06-2011, 10:38 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Assuming what grail says, try using -execdir instead of -exec.
 
  


Reply



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
[SOLVED] bash calling recursively a script patolfo Programming 8 03-29-2010 11:38 AM
Bash script to rename photos in directory & all subdirectories shy_guest Linux - Software 7 09-02-2009 01:40 PM
Using Bash, Find script files in a directory or subdirectories within... ray5_83 Programming 4 10-10-2008 07:42 PM
osx bash script help? babag Programming 4 01-30-2007 07:32 PM
Bash script - executing a script through subdirectories bubkus_jones Programming 5 04-24-2006 05:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:27 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
Open Source Consulting | Domain Registration