Skip to content

Commit cbc3ac2

Browse files
committed
refactor: l.is_exported use l.var_attrs
1 parent 2e6dea6 commit cbc3ac2

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/modules/is_exported.bash

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,11 @@
88
# Notice: Only with bash 4.3, this function return 1 when the exported variable declared without initialization.
99
# Notice: Because `declare -p a` shows `declare: a: not found` when `declare -a a`. It's a bug in bash 4.3.
1010
# Notice: In bash 4.0~4.3, when `export <var>` without initialization, is_exported will return false. Because `declare -p <var>` will print "not found". It's a bug in Bash.
11+
# Dependent: var_attrs
1112
# ---
1213

1314
l.is_exported() {
14-
local s
15-
if s=$(declare -p "$1" 2>/dev/null) ;then
16-
s=$(echo "$s" | sed -E 's/^declare ([-a-zA-Z]+) .+/\1/')
17-
if [[ $s == *x* ]]; then
18-
return 0
19-
else
20-
return 1
21-
fi
22-
else
23-
return 1
24-
fi
15+
local attrs
16+
attrs=$(l.var_attrs "$1")
17+
[[ $attrs == *x* ]]
2518
}

0 commit comments

Comments
 (0)