diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-07-16 16:48:14 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-07-16 17:16:08 -0400 |
commit | 853ffb8e5361cc00c0a4f0970f5c04f931498a03 (patch) | |
tree | 830eafa241c51e6d86acc8ac4a12d8576db02b6d | |
parent | 76278801e7012e33b0f501858ca050983e07215d (diff) |
common.sh.in: ary=($(...)) isn't safe; use readarray
-rw-r--r-- | common.sh.in | 18 |
1 files 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: |