簡體   English   中英

為什么這個來自 git ls-remote 的正則表達式不能正常工作?

[英]why this regex from git ls-remote is not working as it should be?

如果我做 :

echo From ssh://azeaze@azaz.git | grep -oh From.* | grep -oh ssh.*git

我得到了例外,即:

ssh://azeaze@azaz.git

但如果我這樣做:

git ls-remote | grep -oh From.* | grep -oh ssh.*git

我得到以下輸出:

From ssh://azeaze@azaz.git

為什么?

“from” 行轉到 stderr,因此 grep 會忽略它。 將 stderr 重定向到 stdout 以將其通過管道傳輸到 grep:

git ls-remote 2>&1 | grep -o 'From.*' | grep -o 'ssh.*git'

小改動:grepp 標准輸入時不需要-h 引用模式以防止 shell 擴展通配符。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM