busybox/shell/ash_test/ash-vars/var_backslash1.tests
Denys Vlasenko 0da6c813e1 hush: fix var_backslash1.tests
function                                             old     new   delta
o_addqblock                                            -     131    +131
append_str_maybe_ifs_split                            53     100     +47
expand_one_var                                      1872    1897     +25
encode_then_expand_vararg                            380     399     +19
sig_unblock                                           41      43      +2
sig_block                                             41      40      -1
sigprocmask_allsigs                                   33      31      -2
expand_vars_to_list                                 1080    1077      -3
wait_for_child_or_signal                             202     193      -9
o_addQstr                                            175      42    -133
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/5 up/down: 224/-148)           Total: 76 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-11 17:36:02 +02:00

48 lines
3.2 KiB
Text
Executable file

a='\*bc'
b='\'
c='*'
echo "a is '$a'"
echo "b is '$b'"
echo "c is '$c'"
echo '${a##?*} removes everything: '"|${a##?*}|"' - matches one char, then all'
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 nothing: '"|${a##\\\$c}|"' - matches \, but then second char is not $'
echo '${a##\\"$c"} removes \*: '"|${a##\\"$c"}|"' - matches \, then *'
echo '${a##$b} removes \: '"|${a##$b}|"' - matches \'
echo '${a##"$b"} removes \: '"|${a##"$b"}|"' - matches \'
echo
sq="'"
echo 'Single quote tests:'
echo '${a##?'$sq'*'$sq'} removes \*: '"|${a##?'*'}|"' - matches one char, then *'
echo '${a##'$sq'\'$sq'*} removes everything: '"|${a##'\'*}|"' - matches \, then all'
echo '${a##'$sq'\'$sq'\*} removes \*: '"|${a##'\'\*}|"' - matches \, then *'
echo '${a##'$sq'\*'$sq'} removes \*: '"|${a##'\*'}|"' - matches \, then *'
echo '${a##'$sq'\'$sq'$c} removes everything: '"|${a##'\'$c}|"' - matches \, then all'
echo '${a##'$sq'\'$sq'\$c} removes nothing: '"|${a##'\'\$c}|"' - matches \, but then second char is not $'
echo '${a##'$sq'\'$sq'"$c"} removes \*: '"|${a##'\'"$c"}|"' - matches \, then *'
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 *'