diff options
Diffstat (limited to 'shell/ash_test/ash-vars')
-rw-r--r-- | shell/ash_test/ash-vars/var_bash4.right | 25 | ||||
-rwxr-xr-x | shell/ash_test/ash-vars/var_bash4.tests | 52 | ||||
-rw-r--r-- | shell/ash_test/ash-vars/var_bash5.right | 13 | ||||
-rwxr-xr-x | shell/ash_test/ash-vars/var_bash5.tests | 24 | ||||
-rw-r--r-- | shell/ash_test/ash-vars/var_posix1.right | 30 | ||||
-rwxr-xr-x | shell/ash_test/ash-vars/var_posix1.tests | 37 |
6 files changed, 156 insertions, 25 deletions
diff --git a/shell/ash_test/ash-vars/var_bash4.right b/shell/ash_test/ash-vars/var_bash4.right index 600e853..0ef1bf6 100644 --- a/shell/ash_test/ash-vars/var_bash4.right +++ b/shell/ash_test/ash-vars/var_bash4.right @@ -1,23 +1,40 @@ Source: a*b\*c Replace str: _\\_\z_ Pattern: single backslash and star: "replace literal star" -In assignment: a_\_z_b\*c Unquoted: a_\_z_b\*c +Unquoted =: a_\_z_b\*c Quoted: a_\_\z_b\*c +Quoted =: a_\_\z_b\*c Pattern: double backslash and star: "replace backslash and everything after it" -In assignment: a*b_\_z_ Unquoted: a*b_\_z_ +Unquoted =: a*b_\_z_ Quoted: a*b_\_\z_ +Quoted =: a*b_\_\z_ Source: a\bc Replace str: _\\_\z_ Pattern: single backslash and b: "replace b" -In assignment: a\_\_z_c Unquoted: a\_\_z_c +Unquoted =: a\_\_z_c Quoted: a\_\_\z_c +Quoted =: a\_\_\z_c Pattern: double backslash and b: "replace backslash and b" -In assignment: a_\_z_c Unquoted: a_\_z_c +Unquoted =: a_\_z_c Quoted: a_\_\z_c +Quoted =: a_\_\z_c + +Source: a\bc +Replace str: _\\_\z_ (as variable $s) +Pattern: single backslash and b: "replace b" +Unquoted: a\_\\_\z_c +Unquoted =: a\_\\_\z_c +Quoted: a\_\\_\z_c +Quoted =: a\_\\_\z_c +Pattern: double backslash and b: "replace backslash and b" +Unquoted: a_\\_\z_c +Unquoted =: a_\\_\z_c +Quoted: a_\\_\z_c +Quoted =: a_\\_\z_c Done: 0 diff --git a/shell/ash_test/ash-vars/var_bash4.tests b/shell/ash_test/ash-vars/var_bash4.tests index d547061..32aa2b3 100755 --- a/shell/ash_test/ash-vars/var_bash4.tests +++ b/shell/ash_test/ash-vars/var_bash4.tests @@ -6,23 +6,30 @@ # even in quotes. # # bash4 (and probably bash3 too): "Quoted:" results are different from -# unquoted and assignment expansions - they have a backslash before z. +# unquoted expansions - they have a backslash before z. +# +# The difference only exists if repl is a literal. If it is a variable: +# ${v/.../$s}, then all backslashes are preserved in both cases. v='a*b\*c' echo 'Source: ' "$v" echo 'Replace str: ' '_\\_\z_' echo 'Pattern: ' 'single backslash and star: "replace literal star"' -r=${v/\*/_\\_\z_} -echo 'In assignment:' "$r" echo 'Unquoted: ' ${v/\*/_\\_\z_} +r=${v/\*/_\\_\z_} +echo 'Unquoted =: ' "$r" echo 'Quoted: ' "${v/\*/_\\_\z_}" +r="${v/\*/_\\_\z_}" +echo 'Quoted =: ' "$r" echo 'Pattern: ' 'double backslash and star: "replace backslash and everything after it"' -r=${v/\\*/_\\_\z_} -echo 'In assignment:' "$r" echo 'Unquoted: ' ${v/\\*/_\\_\z_} +r=${v/\\*/_\\_\z_} +echo 'Unquoted =: ' "$r" echo 'Quoted: ' "${v/\\*/_\\_\z_}" +r="${v/\\*/_\\_\z_}" +echo 'Quoted =: ' "$r" echo @@ -31,16 +38,43 @@ echo 'Source: ' "$v" echo 'Replace str: ' '_\\_\z_' echo 'Pattern: ' 'single backslash and b: "replace b"' -r=${v/\b/_\\_\z_} -echo 'In assignment:' "$r" echo 'Unquoted: ' ${v/\b/_\\_\z_} +r=${v/\b/_\\_\z_} +echo 'Unquoted =: ' "$r" echo 'Quoted: ' "${v/\b/_\\_\z_}" +r="${v/\b/_\\_\z_}" +echo 'Quoted =: ' "$r" echo 'Pattern: ' 'double backslash and b: "replace backslash and b"' -r=${v/\\b/_\\_\z_} -echo 'In assignment:' "$r" echo 'Unquoted: ' ${v/\\b/_\\_\z_} +r=${v/\\b/_\\_\z_} +echo 'Unquoted =: ' "$r" echo 'Quoted: ' "${v/\\b/_\\_\z_}" +r="${v/\\b/_\\_\z_}" +echo 'Quoted =: ' "$r" + +echo + +v='a\bc' +s='_\\_\z_' +echo 'Source: ' "$v" +echo 'Replace str: ' "$s" '(as variable $s)' + +echo 'Pattern: ' 'single backslash and b: "replace b"' +echo 'Unquoted: ' ${v/\b/$s} +r=${v/\b/$s} +echo 'Unquoted =: ' "$r" +echo 'Quoted: ' "${v/\b/$s}" +r="${v/\b/$s}" +echo 'Quoted =: ' "$r" + +echo 'Pattern: ' 'double backslash and b: "replace backslash and b"' +echo 'Unquoted: ' ${v/\\b/$s} +r=${v/\\b/$s} +echo 'Unquoted =: ' "$r" +echo 'Quoted: ' "${v/\\b/$s}" +r="${v/\\b/$s}" +echo 'Quoted =: ' "$r" echo diff --git a/shell/ash_test/ash-vars/var_bash5.right b/shell/ash_test/ash-vars/var_bash5.right index 278ed32..1990902 100644 --- a/shell/ash_test/ash-vars/var_bash5.right +++ b/shell/ash_test/ash-vars/var_bash5.right @@ -1,4 +1,11 @@ -a/ -a/d -a/e/f +1 a/ +2 a/d +3 a/e/f +4 a\ +5 a\d +6 a\e\f +7 a\\ +8 a\\d +9 a\\e\\f +a ab Done: 0 diff --git a/shell/ash_test/ash-vars/var_bash5.tests b/shell/ash_test/ash-vars/var_bash5.tests index 7f482a5..5748b4a 100755 --- a/shell/ash_test/ash-vars/var_bash5.tests +++ b/shell/ash_test/ash-vars/var_bash5.tests @@ -4,8 +4,26 @@ v='a/b/c' s='b/c' r='e/f' -echo "${v/$s}" -echo "${v/$s/d}" -echo "${v/$s/$r}" +echo "1 ${v/$s}" +echo "2 ${v/$s/d}" +echo "3 ${v/$s/$r}" + +v='a\b\c' +s='b\\c' +r='e\f' +echo "4 ${v/$s}" +echo "5 ${v/$s/d}" +echo "6 ${v/$s/$r}" + +v='a\\b\\c' +s='b\\\\c' +r='e\\f' +echo "7 ${v/$s}" +echo "8 ${v/$s/d}" +echo "9 ${v/$s/$r}" + +v='a-$a-\t-\\-\"-\`-\--\z-\*-\?-b' +s='-$a-\\t-\\\\-\\"-\\`-\\--\\z-\\\*-\\\?-' +echo "a ${v/$s}" echo Done: $? diff --git a/shell/ash_test/ash-vars/var_posix1.right b/shell/ash_test/ash-vars/var_posix1.right index 55f3579..7ff618a 100644 --- a/shell/ash_test/ash-vars/var_posix1.right +++ b/shell/ash_test/ash-vars/var_posix1.right @@ -1,3 +1,19 @@ +Empty: +Empty: +Empty: +Empty: +Empty: +Empty: +Empty: +Empty: +Empty: +Empty: +Empty: +Empty: +Empty: +Empty: +Empty: +Empty: abcdcd abcdcd abcdcd @@ -5,7 +21,9 @@ cdcd babcdcd babcdcd ababcdcd - +Empty: +ababcdcd}_tail +ababcdcd_tail ababcd ababcd ababcd @@ -13,5 +31,11 @@ abab ababcdc ababcdc ababcdcd - -end +Empty: +ababcdcd}_tail +ababcdcd_tail +ababcdcd +ab +ab +ab +End diff --git a/shell/ash_test/ash-vars/var_posix1.tests b/shell/ash_test/ash-vars/var_posix1.tests index 4139e2c..82abe81 100755 --- a/shell/ash_test/ash-vars/var_posix1.tests +++ b/shell/ash_test/ash-vars/var_posix1.tests @@ -1,3 +1,25 @@ +unset var + +echo Empty:${var#} +echo Empty:${var##} +echo Empty:${var#*} +echo Empty:${var##*} +echo Empty:${var%} +echo Empty:${var%%} +echo Empty:${var%*} +echo Empty:${var%%*} + +var= + +echo Empty:${var#} +echo Empty:${var##} +echo Empty:${var#*} +echo Empty:${var##*} +echo Empty:${var%} +echo Empty:${var%%} +echo Empty:${var%*} +echo Empty:${var%%*} + var=ababcdcd echo ${var#ab} @@ -7,7 +29,9 @@ echo ${var##a*b} echo ${var#?} echo ${var##?} echo ${var#*} -echo ${var##*} +echo Empty:${var##*} +echo ${var#}}_tail +echo ${var#\}}_tail echo ${var%cd} echo ${var%%cd} @@ -16,6 +40,13 @@ echo ${var%%c*d} echo ${var%?} echo ${var%%?} echo ${var%*} -echo ${var%%*} +echo Empty:${var%%*} +echo ${var#}}_tail +echo ${var#\}}_tail +echo ${var%\\*} + +a=ab}; echo ${a%\}}; +a=abc; c=c; echo ${a%${c}} +a=ab{{c; echo ${a%`echo {{c`} -echo end +echo End |