Archives and Compression
Compression Suffix
Choose an Output Name
Compression tools usually add a suffix to an archive name. A case statement can map a selected method to the output file name.
Program
Play the script to choose a compression method and see the resulting archive name.
compression_suffix.sh
#!/usr/bin/env bash
method=
base="reports.tar"
case "$method" in
gzip) output="${base}.gz" ;;
xz) output="${base}.xz" ;;
none) output="$base" ;;
esac
echo "$output"
#!/usr/bin/env bash
method=
base="reports.tar"
case "$method" in
gzip) output="${base}.gz" ;;
xz) output="${base}.xz" ;;
none) output="$base" ;;
esac
echo "$output"
#!/usr/bin/env bash
method=
base="reports.tar"
case "$method" in
gzip) output="${base}.gz" ;;
xz) output="${base}.xz" ;;
none) output="$base" ;;
esac
echo "$output"
case
`case "$method" in` selects a branch by pattern.
suffix
The chosen method controls the output suffix.
no compression
The `none` branch keeps the original tar archive name.