简体   繁体   中英

What does the shell “${i%,v}” mean in run-parts.sh?

Currently, I am studying crond on Centos7 and want to take a close look at run-parts.sh. But I find some strange scripts such as:

"${i%,v}"

What does it mean? I know ${i%%.\\*} , ${i##.*} , ${i,} , and ${i,,} .

Here is the part script, thanks every one in advance.

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

The syntax ${var%pattern} just expands to the value of $var with the glob pattern matcing 'pattern' removed from the end of the string. So ${i%,v} is just $i with the trailing ,v removed. The only difference between ${i%%,v} and ${i%,v} is that the former will match the longest possible match, but that's irrelevant here since ,v can only expand to the literal string ,v . It's stated best in the documentation ( 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM