shopt -s extglob의 목적은 무엇입니까


15

디렉토리를 제외한 모든 파일을 디렉토리에서 삭제하고 싶었습니다. 내 솔루션을 여기 에서 찾았 습니다 . 이 솔루션은 명령을 사용하고 있습니다

shopt -s extglob

이 명령이 정확히 무엇을하고 있는지, 백엔드 지식을 알고 싶었습니다. 또한이 답변에 대한 의견을 추가했지만 지금까지 회신을받지 못했습니다. 우분투의 새로운 사용자 로서이 명령이 무엇을하는지 궁금합니다.

답변:


16

간단히 말해서 globbing은 패턴 일치를 의미합니다. Bash는 간단한 globbing을 사용 echo l*하여 letter로 시작하는 현재 디렉토리의 파일 목록으로 확장됩니다 l. 물론, 짐작할 수 있듯이 간단하고 제한적입니다.

를 입력하십시오 extglob. 짐작할 수 있듯이,의 약자입니다 extended globbing. 이 옵션을 사용하면 고급 패턴 일치가 가능합니다. 보낸 사람 man bash:

extglob If set, the extended pattern matching features described
        above under Pathname Expansion are enabled.

그리고 그 전에 조금 :

If the extglob shell option is enabled using the shopt builtin, several
extended pattern matching operators are recognized.  In  the  following
description, a pattern-list is a list of one or more patterns separated
by a |.  Composite patterns may be formed using  one  or  more  of  the
following sub-patterns:

      ?(pattern-list)
             Matches zero or one occurrence of the given patterns
      *(pattern-list)
             Matches zero or more occurrences of the given patterns
      +(pattern-list)
             Matches one or more occurrences of the given patterns
      @(pattern-list)
             Matches one of the given patterns
      !(pattern-list)
             Matches anything except one of the given patterns

extglob사용할 수있는 방법에는 여러 가지가 있습니다. Linux Journal 과 Greg 's wiki 에는 좋은 예가 많이 있습니다.

당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.