[hackers] [farbfeld] 2ff: use trap to remove temporary file || FRIGN

From: <git_AT_suckless.org>
Date: Mon, 19 Sep 2016 22:52:34 +0200 (CEST)

commit e9db1f49b75b183c8aeda321ca54aff5b436a4f6
Author: FRIGN <dev_AT_frign.de>
AuthorDate: Mon Sep 19 22:51:45 2016 +0200
Commit: FRIGN <dev_AT_frign.de>
CommitDate: Mon Sep 19 22:51:45 2016 +0200

    2ff: use trap to remove temporary file
    
    This also frees us from having to store the return value somewhere.

diff --git a/2ff b/2ff
index 9a252a9..bf58e5b 100755
--- a/2ff
+++ b/2ff
_AT_@ -5,6 +5,8 @@ if [ "$#" -ne 0 ]; then
 fi
 
 TMP=$(mktemp)
+trap 'rm "$TMP"' EXIT
+
 cat > "$TMP"
 
 if [ "$(dd if="$TMP" bs=1 count=8 2>/dev/null)" = "farbfeld" ]; then
_AT_@ -26,11 +28,9 @@ image/jpeg)
         ;;
 esac
 
-ret=$?
-rm "$TMP"
-
-if [ $ret -ne 0 ]; then
+if [ $? -ne 0 ]; then
         printf "%s: failed to convert from %s\n" "$0" "$FORMAT" >&2
+ exit 1
 fi
 
-exit $ret
+exit 0
Received on Mon Sep 19 2016 - 22:52:34 CEST

This archive was generated by hypermail 2.3.0 : Mon Sep 19 2016 - 23:00:16 CEST