1 |
#!/bin/bash |
2 |
|
3 |
### Remove const suffix |
4 |
v=abcd |
5 |
echo ${v%d} ${v%%cd} |
6 |
# stdout: abc ab |
7 |
|
8 |
### Remove const prefix |
9 |
v=abcd |
10 |
echo ${v#a} ${v##ab} |
11 |
# stdout: bcd cd |
12 |
|
13 |
### Remove const suffix is vectorized on user array |
14 |
a=(1a 2a 3a) |
15 |
argv.py ${a[@]%a} |
16 |
# stdout: ['1', '2', '3'] |
17 |
# status: 0 |
18 |
# N-I dash/mksh stdout-json: "" |
19 |
# N-I dash status: 2 |
20 |
# N-I mksh status: 1 |
21 |
|
22 |
### Remove const suffix is vectorized on $@ array |
23 |
set -- 1a 2a 3a |
24 |
argv.py ${@%a} |
25 |
# stdout: ['1', '2', '3'] |
26 |
# status: 0 |
27 |
# N-I dash stdout: ['1a', '2a', '3'] |
28 |
# N-I dash status: 0 |
29 |
# N-I mksh stdout-json: "" |
30 |
# N-I mksh status: 1 |
31 |
|
32 |
### Remove const suffix from undefined |
33 |
echo ${undef%suffix} |
34 |
# stdout: |
35 |
|
36 |
### Remove smallest glob suffix |
37 |
v=aabbccdd |
38 |
echo ${v%c*} |
39 |
# stdout: aabbc |
40 |
|
41 |
### Remove longest glob suffix |
42 |
v=aabbccdd |
43 |
echo ${v%%c*} |
44 |
# stdout: aabb |
45 |
|
46 |
### Remove smallest glob prefix |
47 |
v=aabbccdd |
48 |
echo ${v#*b} |
49 |
# stdout: bccdd |
50 |
|
51 |
### Remove longest glob prefix |
52 |
v=aabbccdd |
53 |
echo ${v##*b} |
54 |
# stdout: ccdd |
55 |
|