ash: more general format ${var:EXPR:EXPR}

function                                             old     new   delta
subevalvar                                          1171    1202     +31
localcmd                                             364     366      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2017-07-17 17:49:11 +02:00
parent 4f8079de87
commit 826360ff23
3 changed files with 75 additions and 19 deletions

View File

@@ -0,0 +1,23 @@
all |0123456
4: |456
4:2 |45
4:-1 |45
4:-2 |4
4:-3 |
-4: |3456
-4:2 |34
-4:-1 |345
-4:-2 |34
-4:-3 |3
-4:-4 |
-4:i=2 |34
-4:i=-2|34
-4:i=-3|3
-4:i=-4|
-5: |23456
-6: |123456
-7: |0123456
-8: |
-9: |
-9:-99 |
Ok:0

View File

@@ -0,0 +1,24 @@
set -- 0123456
echo "all |"$1
echo "4: |"${1:4}
echo "4:2 |"${1:4:2}
echo "4:-1 |"${1:4:-1}
echo "4:-2 |"${1:4:-2}
echo "4:-3 |"${1:4:-3}
echo "-4: |"${1: -4}
echo "-4:2 |"${1: -4:2}
echo "-4:-1 |"${1: -4:-1}
echo "-4:-2 |"${1: -4:-2}
echo "-4:-3 |"${1: -4:-3}
echo "-4:-4 |"${1: -4:-4}
i=2; echo "-4:i=2 |"${1: -4:i}
i=-2; echo "-4:i=-2|"${1: -4:i}
i=-3; echo "-4:i=-3|"${1: -4:i}
i=-4; echo "-4:i=-4|"${1: -4:i}
echo "-5: |"${1: -5}
echo "-6: |"${1: -6}
echo "-7: |"${1: -7}
echo "-8: |"${1: -8}
echo "-9: |"${1: -9}
echo "-9:-99 |"${1: -9:-99}
echo Ok:$?