The path parameter passed by the shell-function

When writing a script recently, I need to intercept the path parameters passed by the function in the script. I found the following useful methods and recorded them:

file=/dir1/dir2/dir3/my.file.txt

We can replace with ${} to obtain different values:

${file#*/}: Remove the first / and the string to the left: dir1/dir2/dir3/my.file.txt

${file##*/}: Remove the last / and the string to the left: my.file.txt

${file#*.}: Remove the first. and the string to the left: file.txt

${file##*.}: Remove the last one. and the string to the left: txt

${file%/*}: Remove the last entry / and the string to the right: /dir1/dir2/dir3

${file%%/*}: Remove the first / and the string to the right: (empty value)

${file%.*}: Remove the last. and the string to the right: /dir1/dir2/dir3/my.file

${file%%.*}: Remove the first. and the string to the right: /dir1/dir2/dir3/my

Reference address: http://www.jb51.net/article/94355.htm

Guess you like

Origin blog.csdn.net/luolan_hust/article/details/113726478