Reputation: 51
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
Upvotes: 1
Views: 104
Reputation: 212404
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
Upvotes: 3