Step three: Delete matching string
To deal with the default path to your mailbox, for example, can be used directly environment variable MAIL:
[root@svr5 ~]# echo $MAIL
/var/spool/mail/root
1) from left to right, delete the shortest match
format: $ {# variable name keyword}
deleted from the left side of the first character to the nearest part of the keyword "oo", and as a wildcard understand:
[root@svr5 ~]# echo ${MAIL#*oo}
l/mail/root
删除从左侧第1个字符到最近的关键词“/”的部分:
[root@svr5 ~]# echo ${MAIL#*/}
var/spool/mail/root
2) from left to right, the longest match remove
format: $ ## * Image {} variable name
is deleted from the left of the first character to the farthest keyword "oo" section:
[root@svr5 ~]# echo $MAIL //确认变量MAIL的值
/var/spool/mail/root
[root@svr5 ~]# echo ${MAIL##*oo}
t
Delete the first character from the left to the farthest keyword "/" part:
[root@svr5 ~]# echo ${MAIL##*/}
root
Operation $ {MAIL ## * /} effects as the name used to extract substantially the same basename command:
[root@svr5 ~]# basename $MAIL
root
3) from right to left, delete the shortest match
format: $ {variable name} *% Keywords
deleted from the last one character to the right to the left part of the recent keyword "oo", the * wildcard do understand:
[root@svr5 ~]# echo $MAIL //确认变量MAIL的值
[root@svr5 ~]# echo ${MAIL%oo*}
/var/spool/mail/r
Deleted from the last one character to the right to the left nearest the keyword "/" part:
[root@svr5 ~]# echo ${MAIL%/*}
/var/spool/mail
操作 ${MAIL%/*} 的效果与使用dirname命令提取目录名称的效果相同:
[root@svr5 ~]# dirname $MAIL
/var/spool/mail
4) from right to left, the longest matching delete
format: variable name %% $ {*} keyword
deletion of some "oo" from the right side of the last character to the farthest left Keywords:
[root@svr5 ~]# echo $MAIL //确认变量MAIL的值
/var/spool/mail/root
root@svr5 ~]# echo ${MAIL%%oo*}
/var/sp
Deleted from the last one character to the right to the left as far as the keyword "/" part (deleted gone):
[root@svr5 ~]# echo ${MAIL%%/*}
[root@svr5 ~]#