Shopt -s extglob'un amacı nedir


16

Biri hariç tüm dosyaları dizinden silmek istedim. Çözümümü burada buldum . Bu çözüm bir komut kullanıyor

shopt -s extglob

Bu komutun tam olarak ne yaptığını bilmek istedim, bazı arka uç bilgileri. Ben de bu cevaba bir yorum ekledim ama şimdiye kadar cevap alamadım. Ubuntu'ya yeni bir kullanıcı olarak bu komutun ne yaptığını merak ediyorum.

Yanıtlar:


17

Basit bir ifadeyle, globbing, desen eşleşmesini ifade eder. Bash, echo l*geçerli dizindeki harfle başlayan dosyaların listesini genişletmek gibi basit bir globbing kullanır l. Tabii ki, tahmin edebileceğiniz gibi, basit ve sınırlı.

Enter extglob. Tahmin edebileceğiniz gibi, bunun anlamı extended globbing. Bu seçenek daha gelişmiş desen eşleşmesine olanak tanır. Gönderen man bash:

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

Ve bundan biraz önce:

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

Kullanılabilecek çok sayıda yol var extglob. Linux Journal ve Greg'in wiki'sinde oldukça iyi birkaç örnek verilmiştir .

Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.