在 bash 中,如何获取从第一次出现的字符到第二次出现的同一字符的所有内容的子字符串。
例子...
Input String = "abc-def-ghi"
Character = "-"
Desired Output String = "def"
最佳答案
我会使用两个参数扩展。
str="abc-def-ghi"
tmp=${str#*-} # Remove everything up to and including first -
result=${tmp%%-*} # Remove the first - and everything following it
关于string - Bash:从字符第一次出现到第二次出现的子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45921699/