From 09bc36a930319d1287c41b78b24acfb36b0a8715 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 6 Feb 2017 02:55:30 -0500 Subject: lib/common.sh: add 'lock_close'; use it as appropriate. `lock_close FD` is easier to remember than 'exec FD>&-`; and is especially easier if FD is a variable (though that isn't actually taken advantage of here). This uses Bash 4.1+ `exec {var}>&-`, rather than the clunkier `eval exec "$var>&-"` that was necessary in older versions of Bash. Thanks to Dave Reisner for pointing this new bit of syntax out to me the last time I submitted this (back in 2014, 4.1 had just come out). --- lib/common.sh | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/common.sh') diff --git a/lib/common.sh b/lib/common.sh index f6aea93..91a55dc 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -158,6 +158,14 @@ slock() { fi } +## +# usage : lock_close( $fd ) +## +lock_close() { + local fd=$1 + exec {fd}>&- +} + ## # usage: pkgver_equal( $pkgver1, $pkgver2 ) ## -- cgit v1.2.3-54-g00ecf