使用脚本语言在bash中使用字符串的子串

shr*_*wal 1 bash shell

我们如何使用脚本语言从bash中的字符串中获取子字符串?

例:

fullstring="mnuLOCNMOD.URL = javascript:parent.doC...something"
Run Code Online (Sandbox Code Playgroud)

我想要的子字符串是完整字符串中".URL"之前的所有内容.

P.P*_*.P. 5

使用参数扩展,您可以执行以下操作:

fullstring="mnuLOCNMOD.URL = javascript:parent.doC...something"
echo ${fullstring%\.URL*}
Run Code Online (Sandbox Code Playgroud)

打印:

mnuLOCNMOD
Run Code Online (Sandbox Code Playgroud)