Skip to content

Commit a89d834

Browse files
committed
bash: be v4.2 compat
the replacement string in double-quoted pattern substitution does not undergo quote removal, as it does in versions after bash-4.2
1 parent 63fe82c commit a89d834

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

shared/macros/10-bash.jinja

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ There is bash_sed_escape_replacement for replacement escape.
3838
Then escape other than \w and ^ with [ ]. And then ^ with \^.
3939
And use bash replacement to remove \n.
4040
-#}}
41-
{{{ result_variable }}}="$(LC_ALL=C sed 's/[\x01-\x08\x0a-\x1f\x7f]/ /g;s/[^^a-zA-Z0-9_]/[&]/g;s/\^/\\^/g' <<< "{{{ "${" ~ variable ~ "//[$'\n']/ }" }}}")"
41+
{{{ result_variable }}}="$(LC_ALL=C sed 's/[\x01-\x08\x0a-\x1f\x7f]/ /g;s/[^^a-zA-Z0-9_]/[&]/g;s/\^/\\^/g' <<< "{{{ "${" ~ variable ~ "}" }}}" | tr '\n' ' ')"
4242
{{%- endmacro -%}}
4343

4444

@@ -55,9 +55,7 @@ Any control characters are replaced with space except \0 (null character) and
5555

5656
#}}
5757
{{%- macro bash_sed_escape_replacement(variable, result_variable, delim="/") -%}}
58-
{{{ result_variable }}}="{{{ "${" ~ variable }}}//\\/\\\\/}"
59-
{{{ result_variable }}}="{{{ "${" ~ result_variable }}}//[$'\x01-\x08\x0a-\x1f\x7f']/ }"
60-
{{{ result_variable }}}="{{{ "${" ~ result_variable }}}//\{{{ delim }}}/\\\{{{ delim ~ "}" }}}"
58+
{{{ result_variable }}}="$(LC_ALL=C sed 's/[\x01-\x08\x0a-\x1f\x7f]/ /g;s/\\/\\\\/g' <<< "{{{ "${" ~ variable }}}//\{{{ delim }}}/\\\{{{ delim ~ "}" }}}")"
6159
{{%- endmacro -%}}
6260

6361

@@ -1557,8 +1555,7 @@ grep_command+=(-i)
15571555

15581556
# Strip any search characters in the key arg so that the key can be replaced without
15591557
# adding any search characters to the config file.
1560-
stripped_key="{{{ key }}}"
1561-
stripped_key="${stripped_key//[$'^=$,;+']}"
1558+
stripped_key="$(LC_ALL=C sed 's/[\^=$,;+]//g' <<< "{{{ key }}}")"
15621559

15631560
# shellcheck disable=SC2059
15641561
printf -v formatted_output "{{{ format }}}" "${stripped_key}" "{{{ value }}}"

0 commit comments

Comments
 (0)