![]() |
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 |
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. |
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/bashCode:
. script |
| All times are GMT -5. The time now is 05:03 PM. |