# HG changeset patch # User Franz Glasner # Date 1726093721 -7200 # Node ID b379e27cc5833b568ff20dbb6968d391925094c2 # Parent 0ab71eddcfd77cbefe98740c2c1c57714e615852 farray.sh: in farray_join_for_eval(): use dollar-single-quotes only of really needed. Plain single quotes are used otherwise. diff -r 0ab71eddcfd7 -r b379e27cc583 share/local-bsdtools/farray.sh --- 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