You are not logged in.

#1 2010-09-05 14:54:19

orphius1970
Member
From: Modesto (HELL) California
Registered: 2009-02-27
Posts: 151

[solved] Need Help with bash function

I would like to have a bash function that lets me create tar.xz archives. I have the following in my bash now:

mktar() { tar cf  "${1%%/}.tar"     "${1%%/}/"; }
mktgz() { tar czf "${1%%/}.tar.gz"  "${1%%/}/"; }
mktbz() { tar cjf "${1%%/}.tar.bz2" "${1%%/}/"; }

Any advice would be appreciated.

Last edited by orphius1970 (2010-09-06 11:10:39)


AMD Phenomx3, 4gb ram, Nvidia Gforce 9400gt,
MSI K9N2 Diamond Motherboard, Arch x86_64

Offline

#2 2010-09-05 14:55:35

wonder
Developer
From: Bucharest, Romania
Registered: 2006-07-05
Posts: 5,941
Website

Re: [solved] Need Help with bash function

cJf

capital j


Give what you have. To someone, it may be better than you dare to think.

Offline

#3 2010-09-05 14:58:34

Wintervenom
Member
Registered: 2008-08-20
Posts: 1,011

Re: [solved] Need Help with bash function

archive () {
  FILE=$1
  shift
  case $FILE in
    *.tar.bz2) tar -cjf $FILE $* ;;
    *.tar.gz) tar -czf $FILE $* ;;
    *.tar.lzma) tar --lzma -cf $FILE $* ;;
    *.tar.xz) tar --xz -cf $FILE $* ;;
    *.tgz) tar -czf $FILE $* ;;
    *.zip) zip $FILE $* ;;
    *.rar) rar $FILE $* ;;
  esac
}

Offline

#4 2010-09-05 15:10:49

orphius1970
Member
From: Modesto (HELL) California
Registered: 2009-02-27
Posts: 151

Re: [solved] Need Help with bash function

wintervenom,  how do I use that function, an example please


AMD Phenomx3, 4gb ram, Nvidia Gforce 9400gt,
MSI K9N2 Diamond Motherboard, Arch x86_64

Offline

#5 2010-09-05 19:17:48

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: [solved] Need Help with bash function

orphius1970 should learn some shell scripting. smile

$FILE is obviously the archive name and is $1 the first argument.
$* would be the rest of the arguments (only so after the shift command.

So, archive archive_name list of files to be archived.

Example: archive stuff.tar.gz stuff/


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#6 2010-09-06 11:10:23

orphius1970
Member
From: Modesto (HELL) California
Registered: 2009-02-27
Posts: 151

Re: [solved] Need Help with bash function

thank you. now I understand.


AMD Phenomx3, 4gb ram, Nvidia Gforce 9400gt,
MSI K9N2 Diamond Motherboard, Arch x86_64

Offline

Board footer

Powered by FluxBB