Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Directory, dynamically grabbing names

Status
Not open for further replies.

cyprus106

Programmer
Apr 30, 2001
654
I've only got a basic working knowledge of unix shell scripts, so I'm still struggling to get a little more advanced functionality into my sh here...

I'm running a for statement to grab every .tgz file in a particular directory, then I unzip them, one by one, and run the program inside. So I Unzip the tar, run the prog, run a different program, diff the results, then go to the next tar. I don't know how to dynamically grab each program, though. I can't just sed or something for a file name, that I know of, because inside the tar is a qamake.sh, testN.sh, testN.cln, testN.diff... Can anybody tell me how to dynamically grab my shell scripts? I can post my code if necessary. Thanks a lot in advance!

Cyprus
 
Not sure if I understood your reqirements; you may have to give more details about what the contents of your tar file might be.
For a start, you may get a list of all the files in your tar file with 'tar tvf'; then grep for '.sh' and use awk or cut to extract the filename.
Something like
PROG=`tar tvf filename | fgrep .sh | cut -c...`
Does this help?
 
Wewll, basically, after I unzip each test, i.e. test3.tar, inside that tar file is a coordinating shell script, like test3.sh... so basically, forget the tar file and I just need to be able to have the compiler dynamically say "ok this is the tar, now i have to find the specific executable on this." There's 2 scripts, one makefile.sh and the testN.sh one... I need to find whichever one has "make" in it's name first then I need to find whichever one has "test" in it's name after that. For one I just don't know how to do that... and second, there's three files that have "test" in their names, but only one that's a shell script.

Sorry, is that a little clearer now? Thanks a lot for the help so far, that kind of puts me on the right track.

Cyprus
 
Parse the output produced by a tar -t command:
for f in `tar -t test3.tar`
do
case $f in
*make*.sh) : extract and do make stuff;;
*test*.sh) : extract and do test stuff;;
esac
done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top