Variable renaming

This commit is contained in:
krisdoodle45 2021-10-07 09:23:59 +02:00 committed by GitHub
parent 7bb07a62e1
commit d84804d781
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,35 +11,35 @@ while getopts "hc" o; do case "${o}" in
*) printf "Options:\\n -c: Extract archives into current directory rather than a new one.\\n" && exit 1 ;; *) printf "Options:\\n -c: Extract archives into current directory rather than a new one.\\n" && exit 1 ;;
esac done esac done
[ -z "$extracthere" ] && archive="$(realpath "$@" 2>/dev/null)" || archive="$(realpath "${@:2}" 2>/dev/null)" [ -z "$extracthere" ] && archives="$(realpath "$@" 2>/dev/null)" || archives="$(realpath "${@:2}" 2>/dev/null)"
[ -z "$archive" ] && printf "Give archives to extract as argument.\\n" && exit 1 [ -z "$archives" ] && printf "Give archives to extract as argument.\\n" && exit 1
while IFS= read -r f ; do while IFS= read -r file ; do
if [ -f "$f" ] ; then if [ -f "$file" ] ; then
if [ -z "$extracthere" ]; then if [ -z "$extracthere" ]; then
directory="$(echo "$f" | sed 's/\.[^\/.]*$//')" && directory="$(echo "$file" | sed 's/\.[^\/.]*$//')" &&
mkdir -p "$directory" && mkdir -p "$directory" &&
cd "$directory" || continue cd "$directory" || continue
fi fi
case "$f" in case "$file" in
*.tar.bz2|*.tbz2) bsdtar -xf "$f" ;; *.tar.bz2|*.tbz2) bsdtar -xf "$file" ;;
*.tar.xz) bsdtar -xf "$f" ;; *.tar.xz) bsdtar -xf "$file" ;;
*.tar.gz|*.tgz) bsdtar -xf "$f" ;; *.tar.gz|*.tgz) bsdtar -xf "$file" ;;
*.tar.zst) bsdtar -xf "$f" ;; *.tar.zst) bsdtar -xf "$file" ;;
*.tar) bsdtar -xf "$f" ;; *.tar) bsdtar -xf "$file" ;;
*.lzma) unlzma "$f" ;; *.lzma) unlzma "$file" ;;
*.bz2) bunzip2 "$f" ;; *.bz2) bunzip2 "$file" ;;
*.rar) unrar x -ad "$f" ;; *.rar) unrar x -ad "$file" ;;
*.gz) gunzip "$f" ;; *.gz) gunzip "$file" ;;
*.zip) unzip "$f" ;; *.zip) unzip "$file" ;;
*.Z) uncompress "$f" ;; *.Z) uncompress "$file" ;;
*.7z) 7z x "$f" ;; *.7z) 7z x "$file" ;;
*.xz) unxz "$f" ;; *.xz) unxz "$file" ;;
*.exe) cabextract "$f" ;; *.exe) cabextract "$file" ;;
*) printf "extract: '%s' - unknown archive method\\n" "$f" ;; *) printf "extract: '%s' - unknown archive method\\n" "$file" ;;
esac esac
else else
printf "File \"%s\" not found.\\n" "$f" printf "File \"%s\" not found.\\n" "$file"
fi fi
done <<< "$archive" done <<< "$archives"