- 论坛徽章:
- 60
|
语法:
${var#Pattern}, ${var##Pattern}
Remove from $var the shortest/longest part of $Pattern that matches the front end of $var.
${var%Pattern}, ${var%%Pattern}
Remove from $var the shortest/longest part of $Pattern that matches the back end of $var.
[root@hk tmp]# x=a-b+c-d+e-f+g
[root@hk tmp]#
[root@hk tmp]# echo ${x#*-} #从左到右,删除最短匹配
b+c-d+e-f+g
[root@hk tmp]#
[root@hk tmp]# echo ${x##*-} #从左到右,删除最长匹配
f+g
[root@hk tmp]#
[root@hk tmp]# echo ${x%-*} #从右到左,删除最短匹配
a-b+c-d+e
[root@hk tmp]#
[root@hk tmp]# echo ${x%%-*} #从右到左,删除最长匹配
a
[root@hk tmp]#
|
|