Gentoo Archives: gentoo-commits

From: "Robin H. Johnson" <robbat2@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/netifrc:master commit in: sh/
Date: Sun, 21 Apr 2019 04:17:58
Message-Id: 1555820151.1076ace3242611cb6d125f3d18700d363e16be57.robbat2@OpenRC
1 commit: 1076ace3242611cb6d125f3d18700d363e16be57
2 Author: Martin Väth <martin <AT> mvath <DOT> de>
3 AuthorDate: Fri Aug 17 11:11:45 2018 +0000
4 Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
5 CommitDate: Sun Apr 21 04:15:51 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=1076ace3
7
8 sh/functions.sh: Avoid bashisms in shell_var()
9
10 POSIX shells do not provide a substitution operation ${..//..}
11 Negated character classes are marked by [!..] and not [^..] in POSIX.
12
13 Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>
14
15 sh/functions.sh | 10 +++++++++-
16 1 file changed, 9 insertions(+), 1 deletion(-)
17
18 diff --git a/sh/functions.sh b/sh/functions.sh
19 index 5895a90..832e58e 100644
20 --- a/sh/functions.sh
21 +++ b/sh/functions.sh
22 @@ -36,7 +36,15 @@ if [ "$INIT" != "openrc" ]; then
23 shell_var() {
24 local output= sanitized_arg=
25 for arg; do
26 - sanitized_arg="${arg//[^a-zA-Z0-9_]/_}"
27 + sanitized_arg=$arg
28 + while :; do
29 + case $sanitized_arg in
30 + *[!a-zA-Z0-9_]*)
31 + sanitized_arg=${sanitized_arg%%[!a-zA-Z0-9_]*}_${sanitized_arg#*[!a-zA-Z0-9_]}
32 + continue;;
33 + esac
34 + break
35 + done
36 if [ x"$output" = x"" ] ; then
37 output=$sanitized_arg
38 else