Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
changeset 564:b379e27cc583
farray.sh: in farray_join_for_eval(): use dollar-single-quotes only of really needed.
Plain single quotes are used otherwise.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 12 Sep 2024 00:28:41 +0200 |
| parents | 0ab71eddcfd7 |
| children | 55a019e3bddb |
| files | share/local-bsdtools/farray.sh |
| diffstat | 1 files changed, 30 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/share/local-bsdtools/farray.sh Thu Sep 12 00:01:46 2024 +0200 +++ b/share/local-bsdtools/farray.sh Thu Sep 12 00:28:41 2024 +0200 @@ -150,6 +150,31 @@ #: +#: Quote the given input string for eval. +#: +#: If the argument contains a ``'`` character then "Dollar-Single-Quotes" +#: are used; "Single-Quotes" otherwise. +#: +#: Args: +#: $1: The value to be quoted. +#: +#: Output (stdout): +#: The properly quoted string including surrounding quotes. +#: +#: +_farr_quote_for_eval() { + case "${1}" in + *\'*) + _farr_quote_for_eval_dsq "${1}" + ;; + *) + printf "'%s'" "${1}" + ;; + esac +} + + +#: #: Create a new array. #: #: It is assumed that the array does not exist already. @@ -712,7 +737,7 @@ __farr_join_idx=1 while [ ${__farr_join_idx} -le ${__farr_len} ]; do eval __farr_current_value=\"\$\{${__farr_gvrname}_${__farr_join_idx}\}\" - __farr_command="${__farr_command}${__farr_real_separator}$(_farr_quote_for_eval_dsq "${__farr_current_value}")" + __farr_command="${__farr_command}${__farr_real_separator}$(_farr_quote_for_eval "${__farr_current_value}")" __farr_real_separator=' ' __farr_join_idx=$((__farr_join_idx + 1)) done @@ -1522,7 +1547,8 @@ fi farray_destroy TEST || true - farray_create CMD zfs list "-H" "-o" "name,canmount,mounted,mountpoint,origin" "zpool/ROOT/test- YYY" + # shellcheck disable=SC1003 + farray_create CMD zfs list "-H" "-o" "name,canmount,mounted,mountpoint,origin" "zpool/ROOT/test- YYY" "'" '\' 'abc'\''d\tef' farray_join _var CMD echo "CMD: join with ' ': $_var" farray_join _var CMD ' --- ' @@ -1532,7 +1558,8 @@ echo "CMD: join with ' --- ': $_var (empty: ok)" farray_destroy CMD - farray_create CMD zfs list "-H" "-o" "name,canmount,mounted,mountpoint,origin" "zpool/ROOT/test- YYY" + # shellcheck disable=SC1003 + farray_create CMD zfs list "-H" "-o" "name,canmount,mounted,mountpoint,origin" "zpool/ROOT/test- YYY" "'" '\' 'abc'\''d\tef' farray_join_for_eval _var CMD echo "CMD-EVAL: $_var" farray_destroy CMD || true
