본문 바로가기
Programming/Linux

bash - Parameter Expansion

by NAMP 2009. 3. 8.

${parameter#word}

          ${parameter##word}

              The word is expanded to produce a pattern just as in pathname expansion.  If the pattern matches the beginning of the value of parameter, then the result of  the  expansion is the expanded value of parameter with the shortest matching pattern (the ‘‘#’’ case) or the longest matching pattern (the ‘‘##’’ case) deleted.  If parameter  is  @  or  *, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list.  If parameter  is  an  array  variable  subscripted  with @ or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.

 

## 경로명 확장에서처럼 패턴을 만들기 위해 단어가 확장된다. 만약 패턴이 매개변수 값의 첫 부분과 일치하면, 매개변수 값에서 가장 짧은 일치가 일어나는 패턴 내용을 삭제한 값 또는 가장 긴 일치가 일어나는 패턴을 삭제한 값으로 확장한다.

 

 

       ${parameter%word}

       ${parameter%%word}

              The word is expanded to produce a pattern just as in pathname expansion.  If the pattern  matches  a trailing portion of the expanded value of parameter, then the result of the expansion is the expanded value of parameter with the shortest  matching  pattern  (the ‘‘%’’ case) or the longest matching pattern (the ‘‘%%’’ case) deleted.  If parameter is @ or *, the pattern removal operation  is  applied  to  each  positional  parameter in turn, and the expansion is the resultant list.  If parameter is an array variable subscripted with @ or *, the pattern removal operation is  applied  to  each member of the array in turn, and the expansion is the resultant list.

 

%% 경로명 확장에서처럼 패턴을 만들기 위해 단어가 확장된다. 만약 패턴이 매개변수 값의 뒷 부분과 일치하면, 매개변수 값에서 가장 짧은 일치가 일어나는 패턴 내용을 삭제한 값 또는 가장 긴 일치가 일어나는 패턴을 삭제한 값으로 확장한다.

'Programming > Linux' 카테고리의 다른 글

init 명령어와 런레벨  (0) 2009.05.03
리눅스 기본 명령어  (0) 2009.03.10
cmd - source  (0) 2009.03.08
shell - 파일 다루기  (0) 2009.03.08
cmd - ulimit  (0) 2009.03.08

댓글