2016-08-25 14 views
1

#キャラクタの最初のオカレンスをパラメータ置換のbash変数から簡単に取り除く/置き換える方法はありますか? は、私は次のことを試してみましたが、それはうまくいきませんでした:Bashパラメータ置換ストリップファースト#文字

$ VERSION=0.11.3-issue#18.6a0b43d.123 
$ echo ${VERSION#'#'} 
$ echo ${VERSION#\#} 

私は私の出力になりたい:

0.11.3-issue18.6a0b43d.123 
#   ^
#   no # 

このための任意の簡単な解決策?おそらく全く違う方法で?

+1

私はちょうど削除/#文字を置き換えたいです – uloco

答えて

5

#の最初のオカレンスだけを '削除'したい場合は、${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. 
  • 試合はパス名展開(?*を考える)を使用して行われます。
  • さらに、パターンの先頭の#には特別な意味があります。そのため、\に置き換えています。そして、シーケンス\#は、パターンの先頭に#の特別な意味を持たないリテラル#と一致します。

VERSION=0.11.3-issue#18.6a0b43d.123 
echo ${VERSION/\#/} 

出力

0.11.3-issue18.6a0b43d.123 
関連する問題