shell“ $ {i%,v}”在run-parts.sh中是什么意思?

时间:2019-06-24 16:00:01

标签: linux shell

当前,我正在Centos7上研究crond,并希望仔细查看run-parts.sh。但是我发现一些奇怪的脚本,例如:

"${i%,v}"

是什么意思?我知道${i%%.\*}${i##.*}${i,}${i,,}

这是部分脚本,在此先谢谢大家。

for i in $(LC_ALL=C;echo ${1%/}/*[^~,]) ; do
        [ -d $i ] && continue
        # Don't run *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} scripts
        [ "${i%.cfsaved}" != "${i}" ] && continue
        [ "${i%.rpmsave}" != "${i}" ] && continue
        [ "${i%.rpmorig}" != "${i}" ] && continue
        [ "${i%.rpmnew}" != "${i}" ] && continue
        [ "${i%.swp}" != "${i}" ] && continue
        [ "${i%,v}" != "${i}" ] && continue

1 个答案:

答案 0 :(得分:3)

语法${var%pattern}仅扩展到$ var的值,并且从字符串末尾删除了匹配“模式”的全局模式。因此${i%,v}只是$ i,而尾随,v已删除。 ${i%%,v}${i%,v}之间的唯一区别是,前者将匹配最长的匹配项,但这并不相关,因为,v只能扩展为文字字符串,v。最好在文档(http://pubs.opengroup.org/onlinepubs/9699919799/)中声明:

${parameter%[word]}
Remove Smallest Suffix Pattern. The word shall be expanded to produce apattern. The parameter expansion shall then result in parameter, with the smallest portion of the suffix matched by the pattern deleted. If present, word shall not begin with an unquoted '%'.
${parameter%%[word]}
Remove Largest Suffix Pattern. The word shall be expanded to produce a pattern. The parameter expansion shall then result in parameter, with the largest portion of the suffix matched by the pattern deleted