Hallo, hab vor aus einem Dateipfad Informationen wie Dateiname ohne Endung dateinamen, Typ etc zu bestimmen. Leider hilft mir da die Bash Shell nur sehr bedingt weiter s.unten . Funktioniert schon wesentlich besser als erwartet ist aber komplex und nicht gerade sehr schnell.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | ### Usage: script Dateipfad bsp ./script /etc/apt/sources.list ###################### Starting normal extension extraction ########## FILE=$1 FILENAME=`basename "$FILE"` # File name echo $FILE # File variable echo $FILENAME # File name f1=$(echo "$FILENAME" | sed 's/^/./' | rev | cut -d. -f1 | rev) f2=$(echo "$FILENAME" | sed 's/^/./' | rev | cut -d. -f2 | rev) FILETYPE=$(echo $f2$f1) case $FILETYPE in targz) echo "targz" ;; tarxz) echo "tarxz" ;; tarlzma) echo "tarlzma" ;; *) echo $f1 ;; esac |
mfg bluedxca93