add variable

get the first character of the variable
This commit is contained in:
onceupon 2018-04-12 14:23:32 +08:00 committed by GitHub
parent 283d52b361
commit 54a00b2569
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -838,9 +838,17 @@ var="some string"
echo ${#var}
# 11
```
##### get the first character of the variable
```bash
var="some string"
echo ${var%%"${var#?}"}
#s
```
##### replacement (e.g. remove the first leading 0 )
```bash
${var[@]#0}
var="0050"
echo ${var[@]#0}
#050
```
##### replacement (e.g. replace 'a' with ',')