LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 08-20-2005, 10:50 AM   #1
Henster
Member
 
Registered: Jul 2004
Posts: 45

Rep: Reputation: 15
bash script help needed


Hi all,

I'll just quickly explain the script I'm trying to right.

I've got lots of directories containing .rar files that go like this...

file.rar
file.r01
file.r02
file.r03
....
...

I want to run through each directory running the unzip command on file.rar. I think the command has to be run from the directory that contains the .rar because it has to be able to see the sequential files also.

In dodgy code:

Code:
for filename in /startdir/
do
     tar --uncompress $filename
done
I think the problem I'm having at the moment is there are spaces in the file/dir names. So $filename contains non-escaped spaces messing everything up.

Does anyone have a standard script for this kind of thing? I find myself wanting this kind of thing all the time... with programs other than tar too.

Cheers
H
 
Old 08-20-2005, 10:59 AM   #2
mhallbiai
Member
 
Registered: Jun 2005
Posts: 96

Rep: Reputation: 15
have you tried encompassing $filename in quotes
Code:
tar --uncompress "$filename"
i had a problem with a script that would work when i typed the commands manually but when i ran them from the script it would break because of spacing (or other non-escaped characters). After wrapping the $var in quotes all my problems cleared.


hope this helps
 
Old 08-20-2005, 04:40 PM   #3
Henster
Member
 
Registered: Jul 2004
Posts: 45

Original Poster
Rep: Reputation: 15
Cheers

Working now
h
 
Old 08-21-2005, 03:01 AM   #4
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 46
you could also do something like this

Code:
find /startdir/ -iname \*.rar -exec tar --uncompress "{}" \;
it means that it finds any file that ends with .rar in the /startdir/ and when it does it will execute the tar --uncompress command on these files

Last edited by heema; 08-21-2005 at 03:06 AM.
 
Old 08-21-2005, 09:54 AM   #5
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
You can also change your IFS variable to use, say, newline as the field separator in the script. Better to not have spaces in filenames, though, I think that's Bill's attempt to scupper Linux/UNIX.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script. help needed tazthecat Linux - General 2 09-30-2005 01:54 AM
Wrapper needed for BASH Script outspoken Programming 0 01-12-2005 09:04 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM


All times are GMT -5. The time now is 03:00 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration