Denys Vlasenko | f8ddbe1 | 2016-07-25 03:56:00 +0200 | [diff] [blame] | 1 | parameter=abcdef |
| 2 | offset=2 |
| 3 | noffset=-2 |
| 4 | echo "parameter '${parameter}'" |
| 5 | echo "varoffset2 '${parameter:${offset}}'" |
| 6 | echo "varoffset-2 '${parameter:${noffset}}'" |
| 7 | echo "literal '2' '${parameter:2}'" |
Denys Vlasenko | 74d20e6 | 2017-07-06 19:50:42 +0200 | [diff] [blame] | 8 | # This is not interpreted as ${VAR:POS{:LEN}}, |
Denys Vlasenko | f8ddbe1 | 2016-07-25 03:56:00 +0200 | [diff] [blame] | 9 | # but as ${VAR:=WORD} - if VAR is unset or null, substitute WORD |
| 10 | echo "literal '-2' '${parameter:-2}'" |
| 11 | echo "literal ' -2' '${parameter: -2}'" |