在 macbook 上,我試圖編譯一個不包含單詞服務器的檔案夾中的所有原型檔案。Zsh 和 bash 的作業方式似乎與在 Linux 上有點不同。我的同事可以通過使用讓它作業
[^_server]
在 linux 的路徑中。但這在 mac 上似乎不起作用。我設法得到這個
protoc --dart_out=grpc:proto/ ./api/(core|editor|google)/**/*(_server).proto --proto_path=./api
它編譯檔案夾 core、editor 和 google 中檔案名中包含 _server 的所有 proto 檔案。但我需要它是檔案夾 core、editor 和 google 中名稱中不包含 _server 的所有檔案。
uj5u.com熱心網友回復:
嘗試這個:
setopt extendedglob
protoc --dart_out=grpc:proto/ \
./api/(core|editor|google)/**/(^*_server).proto \
--proto_path=./api
下面的 glob 模式演示使用了這個目錄樹:
api/
├── core/
│ ├── core_notserver.proto
│ ├── core_server.proto
│ ├── core_server.txt
│ └── coresub/
│ ├── coresub_notserver.proto
│ └── coresub_server.proto
├── editor/
│ ├── ed_notserver.proto
│ └── ed_server.proto
├── google/
│ ├── ends with excluded letter e.proto
│ ├── ends with included letter a.proto
│ ├── gl_server.proto
│ └── gl_server.txt
└── other/
├── other_notserver.proto
└── other_server.proto
在_server檔案名中:
> print -l ./api/(core|editor|google)/**/*_server.proto
./api/core/core_server.proto
./api/core/coresub/coresub_server.proto
./api/editor/ed_server.proto
./api/google/gl_server.proto
沒有_server在檔案名中。
有兩種方法可以使用zsh- 它們都需要啟用擴展的 glob 模式,使用setopt extendedglob. 該選項只需要設定一次,例如~/.zshrc:
> setopt extendedglob
> print -l ./api/(core|editor|google)/**/(*~*_server).proto
./api/core/core_notserver.proto
./api/core/coresub/coresub_notserver.proto
./api/editor/ed_notserver.proto
./api/google/ends with excluded letter e.proto
./api/google/ends with included letter a.proto
> print -l ./api/(core|editor|google)/**/(^*_server).proto
./api/core/core_notserver.proto
./api/core/coresub/coresub_notserver.proto
./api/editor/ed_notserver.proto
./api/google/ends with excluded letter e.proto
./api/google/ends with included letter a.proto
該模式[^_server]不會給出您正在尋找的結果。使用方括號,這些值將用作單個字符以^從結果中包含或排除。它不被視為序列_server。您的同事可能有一組檔案名,這些檔案名看起來作業正常。
_在這里,任何具有以, s, e,r或結尾的基本部分的檔案名v都將從 glob 結果中排除:
> print -l ./api/(core|editor|google)/**/*[^_server].proto
./api/google/ends with included letter a.proto
有關 globbing 的更多資訊,請參見此處。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/537565.html
標籤:苹果系统zsh
上一篇:從node.js暫停子行程
