以下示例来自我咨询过的众多网页之一。我无法将“从开始移除到标记”或“从标记移除到结束”工作,或许我指定模式的方式有问题?最终目标是从一行文本中删除所有内容,从给定标记到结束。也可以找到一个sed的解决方案,但这个让我烦恼。
VERSION=0.11.3-issue#18.6a0b43d.123
# this one works as expected
echo ${VERSION/\#/}
0.11.3-issue18.6a0b43d.123
# all the others don't, they return the input unchanged
# trying to remove the 'i' to get the syntax straight
echo ${VERSION%i}
0.11.3-issue#18.6a0b43d.123
echo ${VERSION%\i}
0.11.3-issue#18.6a0b43d.123
${VERSION%%\i}
0.11.3-issue#18.6a0b43d.123
echo ${VERSION%%i}
0.11.3-issue#18.6a0b43d.123
答案 0 :(得分:0)
问题是#或%之后的东西不是标记,而是模式。
echo ${VERSION%i*}
添加星号以匹配其余值。