在bash脚本中,当t =“ hello.txt”都
${t %%.txt}和${t%.txt}返回“ hello”
${t ## *.}也是一样,${t#*.}返回“ txt”.
它们之间有区别吗?它们如何工作?
解决方法:
# t="hello.world.txt"
# echo ${t%.*}
hello.world
# echo ${t%%.*}
hello
从bash手册中:
'${ParaMETER%WORD}'
'${ParaMETER%%WORD}'
The WORD is expanded to produce a pattern just as in filename
expansion. If the pattern matches a trailing portion of the
expanded value of ParaMETER, then the result of the expansion is
the value of ParaMETER with the shortest matching pattern (the '%'
case) or the longest matching pattern (the '%%' case) deleted. If
ParaMETER is '@' or '*', the pattern removal operation is applied
to each positional parameter in turn, and the expansion is the
resultant list. If ParaMETER is an array variable subscripted with
'@' or '*', the pattern removal operation is applied to each member
of the array in turn, and the expansion is the resultant list.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。