unpack_tar_gz() { local dir echo echo -n "# Unpacking given tar file $1, using extra options $2 ..." # Check whether the given directory (via -C) exists; if not mkdir it: if [ "${2:0:2}" == "-C" ]; then dir="${2:3}" if [ "${dir:0:1}" != '/' ]; then echo -n " (Warning: Path $dir has no preceding slash - not an absolute path!) " fi [ ! -d "$dir" ] && mkdir -p "$dir" # well, mkdir it. fi tar xzf "$1" $2 ERR=$? if [ "$ERR" -ne 0 ]; then echo echo "# Could not unpack tar file $1!" # Fehlerbehandlung? else echo "ok." fi }