From 853ffb8e5361cc00c0a4f0970f5c04f931498a03 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 16 Jul 2017 16:48:14 -0400 Subject: common.sh.in: ary=($(...)) isn't safe; use readarray --- common.sh.in | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/common.sh.in b/common.sh.in index 54431fe..7b84c1f 100644 --- a/common.sh.in +++ b/common.sh.in @@ -69,27 +69,25 @@ version() { # - emacs_getopt_1 # - emacs_getopt_2 emacs_getopt_init() { - declare ifs="$IFS" - declare -a a_flags - IFS=$'\n' a_flags=($( + readarray -t a_flags < <( LC_ALL=C emacsclient --help | grep ^- | sed -e 's/\s\s.*//' -e 's/, /\n/g' | sed -e 's/[ =].*/:/' -e 's/^-*//' | - grep -vEx 'e|eval')) + grep -vEx 'e|eval' + ) declare -a a_flags_o a_flags_l a_flags_1 a_flags_2 - IFS=$'\n' a_flags_o=($(printf '%s\n' "${a_flags[@]}"|grep -v '^.[^:]')) - IFS=$'\n' a_flags_l=($(printf '%s\n' "${a_flags[@]}"|grep '^.[^:]')) - IFS=$'\n' a_flags_1=($(printf '%s\n' "${a_flags[@]}"|sed -rn -e 's/^(.)$/-\1/p' -e 's/^([^-].*[^:])$/--\1/p')) - IFS=$'\n' a_flags_2=($(printf '%s\n' "${a_flags[@]}"|sed -rn -e 's/^(.):$/-\1/p' -e 's/^([^-].*):$/--\1/p')) + readarray -t a_flags_o < <(printf '%s\n' "${a_flags[@]}"|grep -v '^.[^:]') + readarray -t a_flags_l < <(printf '%s\n' "${a_flags[@]}"|grep '^.[^:]') + readarray -t a_flags_1 < <(printf '%s\n' "${a_flags[@]}"|sed -rn -e 's/^(.)$/-\1/p' -e 's/^([^-].*[^:])$/--\1/p') + readarray -t a_flags_2 < <(printf '%s\n' "${a_flags[@]}"|sed -rn -e 's/^(.):$/-\1/p' -e 's/^([^-].*):$/--\1/p') + local IFS IFS='' emacs_getopt_o="${a_flags_o[*]}" IFS=',' emacs_getopt_l="${a_flags_l[*]}" IFS='|' emacs_getopt_2="^(${a_flags_2[*]})\$" - - IFS=$ifs } # Sets the global variable: -- cgit v1.1-4-g5e80