Example:
1.
File_jpg= "Sample.jpg"
name=${file_jpg%.*}
echo File name is $name
File name is sample
2.
File_jpg= "Sample.jpg"
extension=${file_jpg#*.}
Echo Extension is $extension
File name is jpg
3.
File_name= "www.google.com"
Echo ${file_name%%.*}
Www
4.
File_name= "www.google.com"
Echo ${file_name##*.}
Com
Description
The meaning of ${file_jpg%.*} is to remove the string that matches the wildcard character on the right of% from $file_jpg, and the wildcard character is matched from right to left.
${file_jpg#*.} The meaning is to remove the string that matches the wildcard character on the right side of # from $file_jpg, and the wildcard character matches from left to right.
% belongs to non greedy operation, it finds the shortest result matching wildcard characters from right to left.
Percent percent is not greedy operation, it finds the longest result matching wildcard characters from right to left.
#属于非贪婪操作, it finds the shortest result of matching wildcard characters from left to right.
# #属于非贪婪操作, it finds the longest result of matching wildcard characters from left to right.