summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2015-10-30 20:33:40 (EDT)
committer P. J. McDermott <pj@pehjota.net>2015-10-30 20:33:40 (EDT)
commit3946ad5f53f8f474107870a5592c53b0b42bfe9a (patch)
tree4b2ba254e4ebe605e89fcbe9985568c1cbe998d2
parent0a7498abb0168cea08e49be33c76e2d02e548012 (diff)
downloadfirman.sh-3946ad5f53f8f474107870a5592c53b0b42bfe9a.zip
firman.sh-3946ad5f53f8f474107870a5592c53b0b42bfe9a.tar.gz
firman.sh-3946ad5f53f8f474107870a5592c53b0b42bfe9a.tar.bz2
tools/shmin.sh: Support writing to stdout
-rwxr-xr-xtools/shmin.sh22
1 files changed, 12 insertions, 10 deletions
diff --git a/tools/shmin.sh b/tools/shmin.sh
index d6f35ea..73df7aa 100755
--- a/tools/shmin.sh
+++ b/tools/shmin.sh
@@ -213,16 +213,18 @@ minify()
fi
# Write the output.
- if ! printf '%s\n' "${buffer}" >"${output}~"; then
- die 'Cannot write file "%s"' "${output}~"
- fi
-
- # Set output file name.
- if ! cat "${output}~" >"${output}"; then
- die 'Cannot rename file to "%s"' "${output}"
- fi
- if ! rm "${output}~"; then
- die 'Cannot remove file "%s"' "${output}~"
+ if [ "x${output}" = 'x-' ]; then
+ printf '%s\n' "${buffer}"
+ else
+ if ! printf '%s\n' "${buffer}" >"${output}~"; then
+ die 'Cannot write file "%s"' "${output}~"
+ fi
+ if ! cat "${output}~" >"${output}"; then
+ die 'Cannot rename file to "%s"' "${output}"
+ fi
+ if ! rm "${output}~"; then
+ die 'Cannot remove file "%s"' "${output}~"
+ fi
fi
}