LinuxQuestions.org
Help answer threads with 0 replies.
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 11-22-2003, 09:09 PM   #1
versaulis
Member
 
Registered: Sep 2003
Posts: 139

Rep: Reputation: 15
not that anyone cares but... here's a free decompression script i wrote


this is my first attempt at bash script. it was very hard to figure out (me being a C++ and Java programmer) and i feel like making my own interpreter now. put the script in /usr/bin and associate your .tar.gz .tar and .gz files with it. then all you have to do is click on them once and they will automatically extract to a folder. i'm sure you'll be able to figure out how to add more extentions.

thanks to all the people who helped me figure this thing out!

#!/bin/bash

if [ $# -lt 1 ]
then
echo "Required parameter not provided."
else
#get the lowercase string for string comparing
fFile=`echo $1 | tr [:upper:] [:lower:]`

if [ ${#fFile} -gt 7 ] && [ `expr substr $fFile $(( ${#fFile}-6 )) 7` = ".tar.gz" ]
then
#echo "found .tar.gz"
gunzip -d $fFile
tar -xf `expr substr $fFile 1 $(( ${#fFile}-3 ))`
elif [ `expr substr $fFile $(( ${#fFile}-2 )) 3` = ".gz" ]
then
gunzip -d $fFile
elif [ `expr substr $fFile $(( ${#fFile}-3 )) 4` = ".tar" ]
then
tar -xf $fFile
else
echo "The parameter provided does not end with .tar.gz .tar or .gz"
fi
fi




---newbie note: put this into a text editor and save it... then do a chmod 755 /usr/bin/decompress so that the system *allows you to use it*
 
Old 11-22-2003, 09:24 PM   #2
teval
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Gentoo
Posts: 720

Rep: Reputation: 30
Put everything in [ code ] [ / code ] tags
It'll keep it's formatting

[ `expr substr $fFile $(( ${#fFile}-6 )) 7` = ".tar.gz" ]

Instead of all that.. which is a little messy, I'd do
echo <var>|grep tar.gz

Or.. if you are going to do it that way, use a switch.. and only perform that operation once.
 
Old 11-22-2003, 09:29 PM   #3
versaulis
Member
 
Registered: Sep 2003
Posts: 139

Original Poster
Rep: Reputation: 15
hey dude, this took me hours... i never imagined

myvar=

and

myvar =

would be 2 different things... but yeah, a switch statement would be much better than an else if ladder... but everything that's bash that i touch turns to "bad something-or-other" ... so i'm not going to screw with it anymore tonight!!
 
Old 11-22-2003, 09:29 PM   #4
versaulis
Member
 
Registered: Sep 2003
Posts: 139

Original Poster
Rep: Reputation: 15
and the evil message board took away all my whitespace formatting!!!
 
Old 11-22-2003, 09:40 PM   #5
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally posted by versaulis
and the evil message board took away all my whitespace formatting!!!
Put formatted text with spaces and such inbetween the [code] tags when wanting to keep the format of your scripts, etc in the forums...
 
Old 11-22-2003, 09:42 PM   #6
versaulis
Member
 
Registered: Sep 2003
Posts: 139

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by trickykid
Put formatted text with spaces and such inbetween the [code] tags when wanting to keep the format of your scripts, etc in the forums...

what do you mean by formatted text? how do i do that?
 
Old 11-22-2003, 09:47 PM   #7
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally posted by versaulis
what do you mean by formatted text? how do i do that?
Ummm.. when your making your posts, by default the forums will not read any extra spaces or tabs in your text, if you place them inbetween the code tags by doing something like this:

I put 5 spaces inbetween each word on the following line:

Hey look at this

It will look like this in the forums if you use the [ code ] tags:

Code:
Hey     look     at     this
 
Old 11-22-2003, 09:55 PM   #8
versaulis
Member
 
Registered: Sep 2003
Posts: 139

Original Poster
Rep: Reputation: 15
kewl, ty =)
 
Old 11-23-2003, 03:21 PM   #9
nykey
Member
 
Registered: Nov 2003
Location: Tg-Jiu, Romania
Distribution: OpenSUSE 11.1 / echo "Windows XP" > Trash
Posts: 360

Rep: Reputation: 30
So, versalius can you post the script again with the correct formatting

thanks
 
  


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
Samba fileserver/Ghost Decompression Errors johno12345 Linux - Software 9 08-08-2007 05:41 AM
what is script for rar decompression vijaysh Linux - Software 1 12-22-2004 01:49 PM
7zip's C decompression source lchand_p Linux - General 3 09-30-2004 09:16 AM
Decompression Problem andrewt Linux - Software 3 08-04-2003 04:09 PM
ppp: vj decompression error haknot Linux - Networking 0 01-14-2002 06:39 PM


All times are GMT -5. The time now is 12:38 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration