PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > bash script for different kind of archives.
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

bash script for different kind of archives.

Réponse
 
LinkBack Outils de la discussion
Vieux 08/12/2006, 10h53   #1
slystoner
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut bash script for different kind of archives.

Hi Group,

I'm trying to write a bash script that enter a given dir ($1) and
process all the archive files present in it (zip, rar, ace, tgz, etc).

for every kind of archive the script extract the files (with full paths)
into a new directory with the same name of the archive.

EXAMPLE:

../script.sh /DIR

- enter /DIR
- extract file1.rar into dir "file1"
- extract w w w.zip into dir "w w w"
- and so on.




This is my code, but it' not so good: when I use it on zip files it said:
checkdir: cannot create extraction directory: file1.zip


Note that my script is able only to creato a dir with the same name of
the given file. It should create it without extension!


Thi is the code:

#!/bin/bash

# enter the dir
cd $1

# I use this echo beacuse the file could have spaces into file names
echo "$(ls)" | while read i;
do

if [ $# != 1 ]; then
echo "extract: Bad usage. Syntax \"extract.bash <file>\""
exit 1
else
FILE="$i"
fi

if [ "${FILE//./}" = "$FILE" ]; then
echo "extract: Bad usage. The filename \"$FILE\" has no extension."
exit 1
fi


# manage extensions
EXT=${FILE##*.}

case $EXT in

zip )

unzip $FILE -d $FILE;;

gz |tgz )

gunzip $FILE;;

bz2 )

bunzip2 $FILE ;;

rar )

unrar x $FILE ;;

* )

echo "extract.bash: $FILE has not a valid suffix" 1>&2
exit 1
esac

done

exit 0
  Réponse avec citation
Vieux 08/12/2006, 11h30   #2
slystoner
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash script for different kind of archives.

> Note that my script is able only to creato a dir with the same name of
> the given file. It should create it without extension!
>
> unzip $FILE -d $FILE;;
>


I solved using:
unzip $FILE -d ${FILE%.*} ;;
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h26.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09677 seconds with 10 queries