LinuxQuestions.org
Review your favorite Linux distribution.
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 07-07-2010, 12:00 AM   #1
onuhwt
LQ Newbie
 
Registered: Apr 2010
Posts: 6

Rep: Reputation: 0
running a zip command in a bash script


Hello all, I'm very new to writing bash scripts (wrote my first one this Sunday) and I'm trying to zip a group of files. It has to be in zip format so alternatives like tar won't work here. I have my script in a folder which has a bunch of Sub-directories in the format "Lab\ 3" "Lab\ 5" "Lab\ 6" etc

What I'd like to be able to do is take all of the files (just the contents not the folder itself) in the "Lab\ 3" Folder and put them in Lab3.zip. I'm really close but no matter what I try I keep getting the folders put into the zip file instead of the Folders contents

Code:
#!/bin/bash

LabNum=(3 5 6)

for ARG in ${LabNum[@]};
    do
	` zip -r Lab$ARG Lab\ $ARG/*`
    done
Thanks in advance
 
Old 07-07-2010, 12:11 AM   #2
Elv13
Member
 
Registered: Apr 2006
Location: Montreal,Quebec
Distribution: Gentoo
Posts: 825

Rep: Reputation: 129Reputation: 129
you could add a second level of loop and use zip -g (grow/append) to add each files one after the other. You can "cd" into the directory just before and use
Code:
for FILE in `ls`;do
  zip -g Lab$ARG.zip $FILE
done
I did not tested (you may have to create the archive before?) but it might help you.
 
Old 07-07-2010, 12:45 AM   #3
onuhwt
LQ Newbie
 
Registered: Apr 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Thumbs up Thanks

Quote:
Originally Posted by Elv13 View Post
you could add a second level of loop and use zip -g (grow/append) to add each files one after the other. You can "cd" into the directory just before and use
Code:
for FILE in `ls`;do
  zip -g Lab$ARG.zip $FILE
done
I did not tested (you may have to create the archive before?) but it might help you.
That did exactly what I wanted Thank you very much Elv13. If anyone else stumbles on this thread looking for what I did I'll include the code below. Thanks again

Code:
#!/bin/bash

LabNum=(3 5 6)

for ARG in ${LabNum[@]};
    do
	#zip -r Lab$ARG "Lab\ $ARG/*"
	cd Lab\ $ARG	
	for FILE in `ls`;do
	  zip -g ../Lab$ARG.zip $FILE
	done
        cd ..


    done
 
  


Reply

Tags
bash, script, zip



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] How to make a bash script keep running in same terminal after it calls second script? JohnRock Linux - Newbie 4 06-25-2010 09:16 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM
Running a command as another user in a bash script ran as root? camphor Programming 2 03-29-2009 03:11 PM
bash script - open new window running a command zippity Linux - Newbie 1 07-13-2004 11:16 AM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 01:45 AM

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

All times are GMT -5. The time now is 05:32 PM.

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