Shell 中截取字符串的方式也有很多种。

1
$ str=https://wxnacy.com/2020/01/13/shell-substr

从索引处开始截取

1
2
$ echo ${str:6}
//wxnacy.com/2020/01/13/shell-substr

截取指定长度

1
2
$ echo ${str:6:8}
//wxnacy

从右边索引处开始截取

1
2
$ echo ${str:0-6}
substr
03-16 11:48