From c97908cca1002c078d6b2002f9f62ee9ce882b81 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Thu, 16 Apr 2020 11:11:21 -0700 Subject: bash: untar unpacks rar files --- .bashrc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to '.bashrc') diff --git a/.bashrc b/.bashrc index c1eae32..09b9362 100644 --- a/.bashrc +++ b/.bashrc @@ -644,14 +644,15 @@ func_export add_ssh_keys # Try to detect (tar|zip)file type and unpack accordingly function untar { - local file_type=`file $1 | awk '{ print $2 }'` + local file_type=`file "$1" | awk -F: '{ gsub(/^ +/, "", $2); split($2, p, " "); print p[1] }'` case "$file_type" in - "POSIX") tar -xvf $1 ;; - "bzip2") tar -xvjf $1 ;; - "gzip") tar -xvzf $1 ;; - "XZ") tar -xvJf $1 ;; - "Zip") unzip $1 ;; + "POSIX") tar -xvf "$1" ;; + "bzip2") tar -xvjf "$1" ;; + "gzip") tar -xvzf "$1" ;; + "XZ") tar -xvJf "$1" ;; + "Zip") unzip "$1" ;; + "RAR") unrar x "$1" ;; *) echo "Unable to determine type of tarball." ;; esac -- cgit v1.2.3