Recently write script, need to intercept the path parameter that function passes in the script, discover the following more useful method, record below:
File=/dir1/dir2/dir3/my.file.txt
We can replace each of the different values with ${}:
${file#*/}: Take off the first/and the left string: dir1/dir2/dir3/my.file.txt
${file##*/}: Take off the last one/and the string to the left: My.file.txt
${file#*.} : Take off the first one. and its left string: file.txt
${file##*.} : Take off the last one. and its left string: txt
${file%/*}: Take off the last bar/and the string to the right:/DIR1/DIR2/DIR3
${file%%/*}: Get rid of the first/And right string: (null value)
${FILE%.*}: Take off the last one. and the string to the right:/dir1/dir2/dir3/my.file
${FILE%%.*}: Take off the first one. and the string to the right:/dir1/dir2/dir3/my
Thank you for reading, I hope to help you, thank you for your support for this site!