有没有简单的方法#从参数替换的bash变量中剥离/替换第一次出现的字符?我尝试了以下但它不起作用:
$ VERSION=0.11.3-issue#18.6a0b43d.123
$ echo ${VERSION#'#'}
$ echo ${VERSION#\#}
Run Code Online (Sandbox Code Playgroud)
我希望我的输出是:
0.11.3-issue18.6a0b43d.123
# ^
# no #
Run Code Online (Sandbox Code Playgroud)
对此有什么简单的解决方案 也许是以完全不同的方式?
如果您只想"删除"第一次出现#,请使用${parameter/pattern}.
${parameter/pattern/string}
Pattern substitution. The pattern is expanded to produce a pat-
tern just as in pathname expansion. Parameter is expanded and
the longest match of pattern against its value is replaced with
string. If pattern begins with /, all matches of pattern are
replaced with string. Normally only the first match is
replaced. If pattern begins with #, it must match at the begin-
ning of the expanded value of parameter.
Run Code Online (Sandbox Code Playgroud)
?和*)完成的.#,在模式的开头有一个特殊的含义,这就是我们用它替换它的原因\.然后序列\#匹配文字#而没有#模式开头的特殊含义. 例
VERSION=0.11.3-issue#18.6a0b43d.123
echo ${VERSION/\#/}
Run Code Online (Sandbox Code Playgroud)
产量
0.11.3-issue18.6a0b43d.123
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
109 次 |
| 最近记录: |