Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: base-system@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 2/2] estack.eclass: Use 'shopt -p -o' to restore 'set' flags
Date: Fri, 24 Mar 2017 21:03:04
Message-Id: 20170324210157.27562-2-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH 1/2] eclass/tests/estack_eshopts.sh: Add tests for 'set' variant of eshopt* by "Michał Górny"
1 Use 'shopt -p -o' to obtain the current set of 'set' flags, and to
2 restore them on popping. Unlike $-, it is output in command form (alike
3 'shopt -p'), removing the need for separate logic in eshopts_pop.
4 ---
5 eclass/estack.eclass | 9 ++-------
6 1 file changed, 2 insertions(+), 7 deletions(-)
7
8 diff --git a/eclass/estack.eclass b/eclass/estack.eclass
9 index 19c388f3d8d2..f548abf8c283 100644
10 --- a/eclass/estack.eclass
11 +++ b/eclass/estack.eclass
12 @@ -158,7 +158,7 @@ eshopts_push() {
13 [[ $# -eq 0 ]] && return 0
14 shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*"
15 else
16 - estack_push eshopts $-
17 + estack_push eshopts "$(shopt -p -o)"
18 [[ $# -eq 0 ]] && return 0
19 set "$@" || die "${FUNCNAME}: bad options to set: $*"
20 fi
21 @@ -172,12 +172,7 @@ eshopts_push() {
22 eshopts_pop() {
23 local s
24 estack_pop eshopts s || die "${FUNCNAME}: unbalanced push"
25 - if [[ ${s} == "shopt -"* ]] ; then
26 - eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}"
27 - else
28 - set +$- || die "${FUNCNAME}: sanity: invalid shell settings: $-"
29 - set -${s} || die "${FUNCNAME}: sanity: unable to restore saved shell settings: ${s}"
30 - fi
31 + eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}"
32 }
33
34 # @FUNCTION: eumask_push
35 --
36 2.12.1