1 # This testcase demonstrates that backslashes are treated differently
2 # in 1st and 2nd parts of ${var/search/repl}:
3 # if quoted ("${var/search/repl}"), and repl contains \a (a non-special char),
4 # the backslash in repl stays; if unquoted, backslash is removed.
5 # But search part does not act like that: \a is always converted to just a,
8 # bash4 (and probably bash3 too): "Quoted:" results are different from
9 # unquoted and assignment expansions - they have a backslash before z.
13 echo 'Replace str: ' '_\\_\z_'
15 echo 'Pattern: ' 'single backslash and star: "replace literal star"'
17 echo 'In assignment:' "$r"
18 echo 'Unquoted: ' ${v/\*/_\\_\z_}
19 echo 'Quoted: ' "${v/\*/_\\_\z_}"
21 echo 'Pattern: ' 'double backslash and star: "replace backslash and everything after it"'
23 echo 'In assignment:' "$r"
24 echo 'Unquoted: ' ${v/\\*/_\\_\z_}
25 echo 'Quoted: ' "${v/\\*/_\\_\z_}"
31 echo 'Replace str: ' '_\\_\z_'
33 echo 'Pattern: ' 'single backslash and b: "replace b"'
35 echo 'In assignment:' "$r"
36 echo 'Unquoted: ' ${v/\b/_\\_\z_}
37 echo 'Quoted: ' "${v/\b/_\\_\z_}"
39 echo 'Pattern: ' 'double backslash and b: "replace backslash and b"'
41 echo 'In assignment:' "$r"
42 echo 'Unquoted: ' ${v/\\b/_\\_\z_}
43 echo 'Quoted: ' "${v/\\b/_\\_\z_}"