LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 12-29-2003, 06:36 AM   #1
k0ljat
Member
 
Registered: Apr 2003
Location: Underground
Distribution: Slackware
Posts: 103

Rep: Reputation: 15
Bash script (untar *.tar files and then cd to the untared dir)


I wanted to do a script that would untar all the *.tar files in /home/koljat/ dir, and after untaring them would cd into the untared directory so far i have done this :

Code:
#!/bin/bash
tar -zxvf /home/koljat/*.tar
cd ?????
it untar's files with no error's but the changing directory part is the thing that bothers me..
 
Old 12-29-2003, 07:47 AM   #2
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Lubuntu
Posts: 19,176
Blog Entries: 4

Rep: Reputation: 430Reputation: 430Reputation: 430Reputation: 430Reputation: 430
Why not create an 'untar' directory, move all the tar files into it and then run your script directing the file to cd into whatever your untar directory is.

Your script would then be:

#!/bin/bash
tar -zxvf /home/koljat/*.tar
cd untar

If you look at "man tar" there should be an instruction on how to make files untar into a different directory - similar to the way Winzip can do this.
 
Old 12-30-2003, 05:57 AM   #3
lone_nut
Member
 
Registered: Dec 2003
Location: Denmark
Distribution: Mandrake
Posts: 179

Rep: Reputation: 30
you can't do that, because bash creates a new shell every time you type a new command. The shell script will change directory, but it will then quit leaving you with your original shell and the origial directory.
for your idea to work, you will need to run the script as
. script
(a dot a space and then the name of the script)
instead of
./script
therefore delete the line reading
Code:
#!/bin/bash
and run the script as
Code:
. script
therefore, there is no need for the script to be executable.

Last edited by lone_nut; 12-30-2003 at 05:59 AM.
 
  


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to untar all tar-files in a directory? zoomzoom Linux - Newbie 6 07-22-2009 10:03 AM
Whats the command to untar files that end in .tar.bz2? BaZiL Linux - Newbie 3 06-20-2007 10:51 AM
untar a list of tar files? Rotwang Linux - General 6 10-10-2006 01:34 PM
Tar files in a dir modified before 7 days in a shell script jayachristina Linux - Newbie 4 05-14-2004 02:49 AM
bash script to rm all files in a dir keirobyn Programming 8 07-19-2002 07:53 AM


All times are GMT -5. The time now is 11:28 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