LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 03-10-2008, 10:47 AM   #1
Tordne
Member
 
Registered: Mar 2008
Location: London,UK
Distribution: Ubuntu
Posts: 37

Rep: Reputation: 15
linux coding Question


I'm writing a little code, it's from a tutorial...
Where I'm modifying the tar command, but I want to create a folder with the first variable.

So I wrote: -x) shift ; TARGS="-xvf" ;
mkdir $1 ; cd ./$1 ;
tar $TARGS $1 ;;

But then he gives me an Error message with:"Cannot make the directory, filename already exists!!!"

How can I substract the .tar from $1

With the create command -c it's easy to put the .tar behind it...

Thanks for you're help...
 
Old 03-10-2008, 10:54 AM   #2
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Look at variable substitution/mangling/expansion: http://linuxgazette.net/issue57/eyler.html
 
Old 03-10-2008, 10:56 AM   #3
Tordne
Member
 
Registered: Mar 2008
Location: London,UK
Distribution: Ubuntu
Posts: 37

Original Poster
Rep: Reputation: 15
I already found a little solution,...

-x) shift ; TARGS="-xvf" ;
mkdir $1.x ;
tar $TARGS $1 -C ./$1.x;;

But if somebody knows how I can substract the .tar from my $1 tell me...
 
Old 03-10-2008, 11:02 AM   #4
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Did you look at the link I posted? It has the answer in it; they even give an example.
 
Old 03-10-2008, 11:10 AM   #5
Tordne
Member
 
Registered: Mar 2008
Location: London,UK
Distribution: Ubuntu
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by pwc101 View Post
Did you look at the link I posted? It has the answer in it; they even give an example.
I've just read it, thanks...
but I posted my second one and then I saw yours...

Here's my new solution...

-x) shift ; TARGS="-xvf" ;
mkdir ${1%.tar} ;
tar $TARGS $1 -C ./${1%.tar};;

Thanks now it extracts like it has to...

Last edited by Tordne; 03-10-2008 at 11:17 AM.
 
Old 03-10-2008, 11:12 AM   #6
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
No problem

I use variable mangling all the time to chop file extension off; it saves me a lot of time and is pretty flexible, although at times some of the variables can get a bit hard to read!
 
  


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
Php Coding Question joelhop Programming 2 08-11-2006 12:33 PM
Simple Coding Question joelhop Programming 7 08-08-2006 08:03 PM
PHP Coding Question joelhop Programming 12 07-24-2006 05:52 PM
Coding question quentusrex Programming 11 08-17-2004 09:03 AM
Coding question quentusrex Debian 6 08-16-2004 04:42 AM

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

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