33 lines
486 B
Markdown
33 lines
486 B
Markdown
### 获取变量字符串长度
|
|
```
|
|
➜ ~ url=www.taobao.com
|
|
➜ ~ echo ${#url}
|
|
14
|
|
➜ ~ url=20
|
|
➜ ~ echo ${#url}
|
|
2
|
|
```
|
|
|
|
|
|
### 变量截取
|
|
- 一个 `%` 代表从右往左去掉一个/key/
|
|
- 两个 `%%` 代表从右往左去掉最大/key/
|
|
```
|
|
➜ ~ url=www.taobao.com
|
|
➜ ~ echo ${url%.*}
|
|
www.taobao
|
|
➜ ~ echo ${url%%.*}
|
|
www
|
|
➜ ~
|
|
```
|
|
|
|
- `#` 代表相反方向,从左往右
|
|
```
|
|
➜ ~ url=www.taobao.com
|
|
➜ ~ echo ${url#*.}
|
|
taobao.com
|
|
➜ ~ echo ${url##*.}
|
|
com
|
|
➜ ~
|
|
```
|