aboutsummaryrefslogtreecommitdiff
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)
downloadbusybox-w32-fa82ef1a2ec558bb8e624461851a0d1fcbc0a0b6.tar.gz
busybox-w32-fa82ef1a2ec558bb8e624461851a0d1fcbc0a0b6.tar.bz2
busybox-w32-fa82ef1a2ec558bb8e624461851a0d1fcbc0a0b6.zip
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 @@
1a is '\*bc'
2b is '\'
3c is '*'
4${a##?*} removes everything: ||
5${a##?"*"} removes \*: |bc| - matches one char, then *
6${a##\*} removes nothing: |\*bc| - first char is not *
7${a##\\*} removes everything: || - matches \, then all
8${a##\\\*} removes \*: || - matches \, then *
9${a##?$c} removes everything: || - matches one char, then all
10${a##?"$c"} removes \*: |bc| - matches one char, then *
11${a##\\$c} removes everything: || - matches \, then all
12${a##\\"$c"} removes \*: |bc| - matches \, then *
13${a##$b} removes \: |*bc| - matches \
14${a##"$b"} removes \: |*bc| - matches \
15
16${a##"$b"?} removes \*: |bc| - matches \, then one char
17${a##"$b"*} removes everything: || - matches \, then all
18${a##"$b""?"} removes nothing: |\*bc| - second char is not ?
19${a##"$b""*"} removes \*: |bc| - matches \, then *
20${a##"$b"\*} removes \*: |bc| - matches \, then *
21${a##"$b"$c} removes everything:|| - matches \, then all
22${a##"$b""$c"} removes \*: |bc| - matches \, then *
23${a##"$b?"} removes nothing: |\*bc| - second char is not ?
24${a##"$b*"} removes \*: |bc| - matches \, then *
25${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 @@
1a='\*bc'
2b='\'
3c='*'
4echo "a is '$a'"
5echo "b is '$b'"
6echo "c is '$c'"
7echo '${a##?*} removes everything: '"|${a##?*}|"
8echo '${a##?"*"} removes \*: '"|${a##?"*"}|"' - matches one char, then *'
9echo '${a##\*} removes nothing: '"|${a##\*}|"' - first char is not *'
10echo '${a##\\*} removes everything: '"|${a##\\*}|"' - matches \, then all'
11echo '${a##\\\*} removes \*: '"|${a##\\*}|"' - matches \, then *'
12echo '${a##?$c} removes everything: '"|${a##?$c}|"' - matches one char, then all'
13echo '${a##?"$c"} removes \*: '"|${a##?"$c"}|"' - matches one char, then *'
14echo '${a##\\$c} removes everything: '"|${a##\\$c}|"' - matches \, then all'
15echo '${a##\\"$c"} removes \*: '"|${a##\\"$c"}|"' - matches \, then *'
16echo '${a##$b} removes \: '"|${a##$b}|"' - matches \'
17echo '${a##"$b"} removes \: '"|${a##"$b"}|"' - matches \'
18echo
19## In bash, this isn't working as expected
20#echo '${a##$b?} removes \*: '"|${a##$b?}|"' - matches \, then one char' # bash prints |\*bc|
21#echo '${a##$b*} removes everything: '"|${a##$b*}|"' - matches \, then all' # bash prints |\*bc|
22#echo '${a##$b$c} removes everything: '"|${a##$b$c}|"' - matches \, then all' # bash prints |\*bc|
23#echo '${a##$b"$c"} removes \*: '"|${a##$b"$c"}|"' - matches \, then *' # bash prints |\*bc|
24## the cause seems to be that $b emits backslash that "glues" onto next character if there is one:
25## a='\*bc'; b='\'; c='*'; echo "|${a##?$b*}|" # bash prints |bc| - the $b* works as \* (matches literal *)
26## a='\*bc'; b='\'; c='*'; echo "|${a##\\$b*}|" # bash prints |bc|
27#echo
28echo '${a##"$b"?} removes \*: '"|${a##"$b"?}|"' - matches \, then one char'
29echo '${a##"$b"*} removes everything: '"|${a##"$b"*}|"' - matches \, then all'
30echo '${a##"$b""?"} removes nothing: '"|${a##"$b""?"}|"' - second char is not ?' # bash prints |bc|
31echo '${a##"$b""*"} removes \*: '"|${a##"$b""*"}|"' - matches \, then *'
32echo '${a##"$b"\*} removes \*: '"|${a##"$b"\*}|"' - matches \, then *'
33echo '${a##"$b"$c} removes everything:'"|${a##"$b"$c}|"' - matches \, then all'
34echo '${a##"$b""$c"} removes \*: '"|${a##"$b""$c"}|"' - matches \, then *'
35echo '${a##"$b?"} removes nothing: '"|${a##"$b?"}|"' - second char is not ?' # bash prints |bc|
36echo '${a##"$b*"} removes \*: '"|${a##"$b*"}|"' - matches \, then *' # bash prints ||
37echo '${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 @@
1a is '\*bc'
2b is '\'
3c is '*'
4${a##?*} removes everything: ||
5${a##?"*"} removes \*: |bc| - matches one char, then *
6${a##\*} removes nothing: |\*bc| - first char is not *
7${a##\\*} removes everything: || - matches \, then all
8${a##\\\*} removes \*: || - matches \, then *
9${a##?$c} removes everything: || - matches one char, then all
10${a##?"$c"} removes \*: |bc| - matches one char, then *
11${a##\\$c} removes everything: || - matches \, then all
12${a##\\"$c"} removes \*: |bc| - matches \, then *
13${a##$b} removes \: |*bc| - matches \
14${a##"$b"} removes \: |*bc| - matches \
15
16${a##"$b"?} removes \*: |bc| - matches \, then one char
17${a##"$b"*} removes everything: || - matches \, then all
18${a##"$b""?"} removes nothing: |\*bc| - second char is not ?
19${a##"$b""*"} removes \*: |bc| - matches \, then *
20${a##"$b"\*} removes \*: |bc| - matches \, then *
21${a##"$b"$c} removes everything:|| - matches \, then all
22${a##"$b""$c"} removes \*: |bc| - matches \, then *
23${a##"$b?"} removes nothing: |\*bc| - second char is not ?
24${a##"$b*"} removes \*: |bc| - matches \, then *
25${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 @@
1a='\*bc'
2b='\'
3c='*'
4echo "a is '$a'"
5echo "b is '$b'"
6echo "c is '$c'"
7echo '${a##?*} removes everything: '"|${a##?*}|"
8echo '${a##?"*"} removes \*: '"|${a##?"*"}|"' - matches one char, then *'
9echo '${a##\*} removes nothing: '"|${a##\*}|"' - first char is not *'
10echo '${a##\\*} removes everything: '"|${a##\\*}|"' - matches \, then all'
11echo '${a##\\\*} removes \*: '"|${a##\\*}|"' - matches \, then *'
12echo '${a##?$c} removes everything: '"|${a##?$c}|"' - matches one char, then all'
13echo '${a##?"$c"} removes \*: '"|${a##?"$c"}|"' - matches one char, then *'
14echo '${a##\\$c} removes everything: '"|${a##\\$c}|"' - matches \, then all'
15echo '${a##\\"$c"} removes \*: '"|${a##\\"$c"}|"' - matches \, then *'
16echo '${a##$b} removes \: '"|${a##$b}|"' - matches \'
17echo '${a##"$b"} removes \: '"|${a##"$b"}|"' - matches \'
18echo
19## In bash, this isn't working as expected
20#echo '${a##$b?} removes \*: '"|${a##$b?}|"' - matches \, then one char' # bash prints |\*bc|
21#echo '${a##$b*} removes everything: '"|${a##$b*}|"' - matches \, then all' # bash prints |\*bc|
22#echo '${a##$b$c} removes everything: '"|${a##$b$c}|"' - matches \, then all' # bash prints |\*bc|
23#echo '${a##$b"$c"} removes \*: '"|${a##$b"$c"}|"' - matches \, then *' # bash prints |\*bc|
24## the cause seems to be that $b emits backslash that "glues" onto next character if there is one:
25## a='\*bc'; b='\'; c='*'; echo "|${a##?$b*}|" # bash prints |bc| - the $b* works as \* (matches literal *)
26## a='\*bc'; b='\'; c='*'; echo "|${a##\\$b*}|" # bash prints |bc|
27#echo
28echo '${a##"$b"?} removes \*: '"|${a##"$b"?}|"' - matches \, then one char'
29echo '${a##"$b"*} removes everything: '"|${a##"$b"*}|"' - matches \, then all'
30echo '${a##"$b""?"} removes nothing: '"|${a##"$b""?"}|"' - second char is not ?' # bash prints |bc|
31echo '${a##"$b""*"} removes \*: '"|${a##"$b""*"}|"' - matches \, then *'
32echo '${a##"$b"\*} removes \*: '"|${a##"$b"\*}|"' - matches \, then *'
33echo '${a##"$b"$c} removes everything:'"|${a##"$b"$c}|"' - matches \, then all'
34echo '${a##"$b""$c"} removes \*: '"|${a##"$b""$c"}|"' - matches \, then *'
35echo '${a##"$b?"} removes nothing: '"|${a##"$b?"}|"' - second char is not ?' # bash prints |bc|
36echo '${a##"$b*"} removes \*: '"|${a##"$b*"}|"' - matches \, then *' # bash prints ||
37echo '${a##"$b$c"} removes \*: '"|${a##"$b$c"}|"' - matches \, then *'