Original 52779364
The problem with script development is that the string splitting operation in the original Java (substring indexof, etc.) does not know what to do (e.g./a/b/c/d.txt I want to know the name of the file)
Query information that the shell can use identifiers to do the split string, including substring (0,index) and substring (index,last)
${VAR#*SUBSTR} Removes the last occurrence of a substring from 0 to substr
${VAR##*SUBSTR} will delete the position where the substr begins to the end of the string
${var%substr*} Removes the last part of the string where the string ends
${var%%substr*} will delete the first occurrence of the string to the end of the section
[Plain]View PlainCopy
- A= "/a/b/c/d.txt"
- b= "/"
- echo ${a#* $b}
will return
A/b/c/d.txt
[Plain]View PlainCopy
- A= "/a/b/c/d.txt"
- b= "/"
- echo ${a##* $b}
will return
D.txt
[Plain]View PlainCopy
- A= "/a/b/c/d.txt"
- b= "/"
- echo ${a% $b *}
will return
/a/b/c
[Plain]View PlainCopy
- A= "/a/b/c/d.txt"
- b= "/"
- echo ${a%% $b *}
will return empty
Linux Bash shell string split substring etc (RPM)