Adds Indirection and prefix name expansion (#2102)

This commit is contained in:
Mateus Caruccio 2024-02-14 20:40:36 +00:00 committed by GitHub
parent c7d50cdbe1
commit 7317522a8c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 1 deletions

20
bash.md
View File

@ -173,7 +173,7 @@ echo "${str/foo/bar}" # /path/to/bar.cpp
```bash
str="Hello world"
echo "${str:6:5}" # "world"
echo "${str:6:5}" # "world"
echo "${str: -5:5}" # "world"
```
@ -183,6 +183,24 @@ base=${src##*/} #=> "foo.cpp" (basepath)
dir=${src%$base} #=> "/path/to/" (dirpath)
```
### Prefix name expansion
```bash
prefix_a=one
prefix_b=two
echo ${!prefix_*} # all variables names starting with `prefix_`
prefix_a prefix_b
```
### Indirection
```bash
name=joe
pointer=name
echo ${!pointer}
joe
```
### Substitution
| Code | Description |