[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [shell-script] função extract
From: |
Guilherme Gall |
Subject: |
Re: [shell-script] função extract |
Date: |
Tue, 3 Feb 2009 20:19:23 -0200 |
2009/2/3 voyeg3r <address@hidden>:
> extract () {
> if [ -f $1 ] ; then
> case $1 in
> *.tar.bz2) tar xvjf $1 ;;
> *.tar.gz) tar xvzf $1 ;;
> *.bz2) bunzip2 $1 ;;
> *.rar) rar x $1 ;;
> *.gz) gunzip $1 ;;
> *.tar) tar xvf $1 ;;
> *.tbz2) tar xvjf $1 ;;
> *.tgz) tar xvzf $1 ;;
> *.zip) unzip $1 ;;
> *.Z) uncompress $1 ;;
> *.7z) 7z x $1 ;;
> *) echo "don't know how to extract '$1'..." ;;
> esac
> else
> echo "'$1' is not a valid file!"
> fi
> }
>
> # essa eu peguei aqui:
> # http://wiki.archlinux.org/index.php/Post_Installation_Tips
>
A idéia é interessante, mas seria bom poder passar mais de um arquivo
para extração ou um coringa como *.bz2. Segue essas modificações
abaixo:
#!/bin/bash
extract(){
for file in "$@"; do
if [ -f "$file" ]; then
case "$file" in
*.tar.bz2) tar xvjf "$file";;
*.tar.gz) tar xvzf "$file";;
*.bz2) bunzip2 "$file";;
*.rar) rar x "$file";;
*.gz) gunzip "$file";;
*.tar) tar xvf "$file";;
*.tbz2) tar xvjf "$file";;
*.tgz) tar xvzf "$file";;
*.zip) unzip "$file";;
*.Z) uncompress "$file";;
*.7z) 7z x "$file";;
*) echo "não sei como extrair '$file'...";;
esac
else
echo "'$file' não é um arquivo válido"
fi
done
}
# Fim do script
Fiz uns testes aqui com arquivos com espaço no nome e com o asterisco
para especificar vários arquivos. Aparentemente tudo está funcionando
bem.
Saudações,
--
Guilherme Magalhães Gall (GMGall)
GPG Public Key ID: 0F498058
- função extract, voyeg3r, 2009/02/03
- Re: [shell-script] função extract,
Guilherme Gall <=