Slicing filenames based on extension
Here is practical example that can be used to extract different portions of a domain name,
given URL=”www.google.com”:
$ echo ${URL%.*} # Remove rightmost .*
www.google
$ echo ${URL%%.*} # Remove right to leftmost .* (Greedy operator)
www
$ echo ${URL#*.} # Remove leftmost part before *.
google.com
$ echo ${URL##*.} # Remove left to rightmost part before *. (Greedy operator)
com
还没有评论,来说两句吧...