LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 07: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, 08:47 AM   #2
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
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, 06: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 06: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 13 05-09-2017 12:52 PM
Whats the command to untar files that end in .tar.bz2? BaZiL Linux - Newbie 3 06-20-2007 11:51 AM
untar a list of tar files? Rotwang Linux - General 6 10-10-2006 02:34 PM
Tar files in a dir modified before 7 days in a shell script jayachristina Linux - Newbie 4 05-14-2004 03:49 AM
bash script to rm all files in a dir keirobyn Programming 8 07-19-2002 08:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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