summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2025-08-09 01:48:12 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2025-08-09 01:48:12 +0200
commitfa82ef1a2ec558bb8e624461851a0d1fcbc0a0b6 (patch)
tree09075923325628a7b39d8f6c0bcef71f7cc4dd84 /shell
parent5b3405594a8925d4590c21e02adeabf85d34d93e (diff)
shells: add testsuite item
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/ash_test/ash-vars/var_backslash1.right25
-rwxr-xr-xshell/ash_test/ash-vars/var_backslash1.tests37
-rw-r--r--shell/hush_test/hush-bugs/var_backslash1.right25
-rwxr-xr-xshell/hush_test/hush-bugs/var_backslash1.tests37
4 files changed, 124 insertions, 0 deletions
diff --git a/shell/ash_test/ash-vars/var_backslash1.right b/shell/ash_test/ash-vars/var_backslash1.right
new file mode 100644
index 000000000..066294838
--- /dev/null
+++ b/shell/ash_test/ash-vars/var_backslash1.right
@@ -0,0 +1,25 @@
+a is '\*bc'
+b is '\'
+c is '*'
+${a##?*} removes everything: ||
+${a##?"*"} removes \*: |bc| - matches one char, then *
+${a##\*} removes nothing: |\*bc| - first char is not *
+${a##\\*} removes everything: || - matches \, then all
+${a##\\\*} removes \*: || - matches \, then *
+${a##?$c} removes everything: || - matches one char, then all
+${a##?"$c"} removes \*: |bc| - matches one char, then *
+${a##\\$c} removes everything: || - matches \, then all
+${a##\\"$c"} removes \*: |bc| - matches \, then *
+${a##$b} removes \: |*bc| - matches \
+${a##"$b"} removes \: |*bc| - matches \
+
+${a##"$b"?} removes \*: |bc| - matches \, then one char
+${a##"$b"*} removes everything: || - matches \, then all
+${a##"$b""?"} removes nothing: |\*bc| - second char is not ?
+${a##"$b""*"} removes \*: |bc| - matches \, then *
+${a##"$b"\*} removes \*: |bc| - matches \, then *
+${a##"$b"$c} removes everything:|| - matches \, then all
+${a##"$b""$c"} removes \*: |bc| - matches \, then *
+${a##"$b?"} removes nothing: |\*bc| - second char is not ?
+${a##"$b*"} removes \*: |bc| - matches \, then *
+${a##"$b$c"} removes \*: |bc| - matches \, then *
diff --git a/shell/ash_test/ash-vars/var_backslash1.tests b/shell/ash_test/ash-vars/var_backslash1.tests
new file mode 100755
index 000000000..7d865c929
--- /dev/null
+++ b/shell/ash_test/ash-vars/var_backslash1.tests
@@ -0,0 +1,37 @@
+a='\*bc'
+b='\'
+c='*'
+echo "a is '$a'"
+echo "b is '$b'"
+echo "c is '$c'"
+echo '${a##?*} removes everything: '"|${a##?*}|"
+echo '${a##?"*"} removes \*: '"|${a##?"*"}|"' - matches one char, then *'
+echo '${a##\*} removes nothing: '"|${a##\*}|"' - first char is not *'
+echo '${a##\\*} removes everything: '"|${a##\\*}|"' - matches \, then all'
+echo '${a##\\\*} removes \*: '"|${a##\\*}|"' - matches \, then *'
+echo '${a##?$c} removes everything: '"|${a##?$c}|"' - matches one char, then all'
+echo '${a##?"$c"} removes \*: '"|${a##?"$c"}|"' - matches one char, then *'
+echo '${a##\\$c} removes everything: '"|${a##\\$c}|"' - matches \, then all'
+echo '${a##\\"$c"} removes \*: '"|${a##\\"$c"}|"' - matches \, then *'
+echo '${a##$b} removes \: '"|${a##$b}|"' - matches \'
+echo '${a##"$b"} removes \: '"|${a##"$b"}|"' - matches \'
+echo
+## In bash, this isn't working as expected
+#echo '${a##$b?} removes \*: '"|${a##$b?}|"' - matches \, then one char' # bash prints |\*bc|
+#echo '${a##$b*} removes everything: '"|${a##$b*}|"' - matches \, then all' # bash prints |\*bc|
+#echo '${a##$b$c} removes everything: '"|${a##$b$c}|"' - matches \, then all' # bash prints |\*bc|
+#echo '${a##$b"$c"} removes \*: '"|${a##$b"$c"}|"' - matches \, then *' # bash prints |\*bc|
+## the cause seems to be that $b emits backslash that "glues" onto next character if there is one:
+## a='\*bc'; b='\'; c='*'; echo "|${a##?$b*}|" # bash prints |bc| - the $b* works as \* (matches literal *)
+## a='\*bc'; b='\'; c='*'; echo "|${a##\\$b*}|" # bash prints |bc|
+#echo
+echo '${a##"$b"?} removes \*: '"|${a##"$b"?}|"' - matches \, then one char'
+echo '${a##"$b"*} removes everything: '"|${a##"$b"*}|"' - matches \, then all'
+echo '${a##"$b""?"} removes nothing: '"|${a##"$b""?"}|"' - second char is not ?' # bash prints |bc|
+echo '${a##"$b""*"} removes \*: '"|${a##"$b""*"}|"' - matches \, then *'
+echo '${a##"$b"\*} removes \*: '"|${a##"$b"\*}|"' - matches \, then *'
+echo '${a##"$b"$c} removes everything:'"|${a##"$b"$c}|"' - matches \, then all'
+echo '${a##"$b""$c"} removes \*: '"|${a##"$b""$c"}|"' - matches \, then *'
+echo '${a##"$b?"} removes nothing: '"|${a##"$b?"}|"' - second char is not ?' # bash prints |bc|
+echo '${a##"$b*"} removes \*: '"|${a##"$b*"}|"' - matches \, then *' # bash prints ||
+echo '${a##"$b$c"} removes \*: '"|${a##"$b$c"}|"' - matches \, then *'
diff --git a/shell/hush_test/hush-bugs/var_backslash1.right b/shell/hush_test/hush-bugs/var_backslash1.right
new file mode 100644
index 000000000..066294838
--- /dev/null
+++ b/shell/hush_test/hush-bugs/var_backslash1.right
@@ -0,0 +1,25 @@
+a is '\*bc'
+b is '\'
+c is '*'
+${a##?*} removes everything: ||
+${a##?"*"} removes \*: |bc| - matches one char, then *
+${a##\*} removes nothing: |\*bc| - first char is not *
+${a##\\*} removes everything: || - matches \, then all
+${a##\\\*} removes \*: || - matches \, then *
+${a##?$c} removes everything: || - matches one char, then all
+${a##?"$c"} removes \*: |bc| - matches one char, then *
+${a##\\$c} removes everything: || - matches \, then all
+${a##\\"$c"} removes \*: |bc| - matches \, then *
+${a##$b} removes \: |*bc| - matches \
+${a##"$b"} removes \: |*bc| - matches \
+
+${a##"$b"?} removes \*: |bc| - matches \, then one char
+${a##"$b"*} removes everything: || - matches \, then all
+${a##"$b""?"} removes nothing: |\*bc| - second char is not ?
+${a##"$b""*"} removes \*: |bc| - matches \, then *
+${a##"$b"\*} removes \*: |bc| - matches \, then *
+${a##"$b"$c} removes everything:|| - matches \, then all
+${a##"$b""$c"} removes \*: |bc| - matches \, then *
+${a##"$b?"} removes nothing: |\*bc| - second char is not ?
+${a##"$b*"} removes \*: |bc| - matches \, then *
+${a##"$b$c"} removes \*: |bc| - matches \, then *
diff --git a/shell/hush_test/hush-bugs/var_backslash1.tests b/shell/hush_test/hush-bugs/var_backslash1.tests
new file mode 100755
index 000000000..7d865c929
--- /dev/null
+++ b/shell/hush_test/hush-bugs/var_backslash1.tests
@@ -0,0 +1,37 @@
+a='\*bc'
+b='\'
+c='*'
+echo "a is '$a'"
+echo "b is '$b'"
+echo "c is '$c'"
+echo '${a##?*} removes everything: '"|${a##?*}|"
+echo '${a##?"*"} removes \*: '"|${a##?"*"}|"' - matches one char, then *'
+echo '${a##\*} removes nothing: '"|${a##\*}|"' - first char is not *'
+echo '${a##\\*} removes everything: '"|${a##\\*}|"' - matches \, then all'
+echo '${a##\\\*} removes \*: '"|${a##\\*}|"' - matches \, then *'
+echo '${a##?$c} removes everything: '"|${a##?$c}|"' - matches one char, then all'
+echo '${a##?"$c"} removes \*: '"|${a##?"$c"}|"' - matches one char, then *'
+echo '${a##\\$c} removes everything: '"|${a##\\$c}|"' - matches \, then all'
+echo '${a##\\"$c"} removes \*: '"|${a##\\"$c"}|"' - matches \, then *'
+echo '${a##$b} removes \: '"|${a##$b}|"' - matches \'
+echo '${a##"$b"} removes \: '"|${a##"$b"}|"' - matches \'
+echo
+## In bash, this isn't working as expected
+#echo '${a##$b?} removes \*: '"|${a##$b?}|"' - matches \, then one char' # bash prints |\*bc|
+#echo '${a##$b*} removes everything: '"|${a##$b*}|"' - matches \, then all' # bash prints |\*bc|
+#echo '${a##$b$c} removes everything: '"|${a##$b$c}|"' - matches \, then all' # bash prints |\*bc|
+#echo '${a##$b"$c"} removes \*: '"|${a##$b"$c"}|"' - matches \, then *' # bash prints |\*bc|
+## the cause seems to be that $b emits backslash that "glues" onto next character if there is one:
+## a='\*bc'; b='\'; c='*'; echo "|${a##?$b*}|" # bash prints |bc| - the $b* works as \* (matches literal *)
+## a='\*bc'; b='\'; c='*'; echo "|${a##\\$b*}|" # bash prints |bc|
+#echo
+echo '${a##"$b"?} removes \*: '"|${a##"$b"?}|"' - matches \, then one char'
+echo '${a##"$b"*} removes everything: '"|${a##"$b"*}|"' - matches \, then all'
+echo '${a##"$b""?"} removes nothing: '"|${a##"$b""?"}|"' - second char is not ?' # bash prints |bc|
+echo '${a##"$b""*"} removes \*: '"|${a##"$b""*"}|"' - matches \, then *'
+echo '${a##"$b"\*} removes \*: '"|${a##"$b"\*}|"' - matches \, then *'
+echo '${a##"$b"$c} removes everything:'"|${a##"$b"$c}|"' - matches \, then all'
+echo '${a##"$b""$c"} removes \*: '"|${a##"$b""$c"}|"' - matches \, then *'
+echo '${a##"$b?"} removes nothing: '"|${a##"$b?"}|"' - second char is not ?' # bash prints |bc|
+echo '${a##"$b*"} removes \*: '"|${a##"$b*"}|"' - matches \, then *' # bash prints ||
+echo '${a##"$b$c"} removes \*: '"|${a##"$b$c"}|"' - matches \, then *'