|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
> 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%.*} ;; |
|
![]() |
| Outils de la discussion | |
|
|