2016-08-25 4 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 
난 그냥 제거 할