![](/img/trans.png)
[英]Trying to work out why this regex is not working? Regex should be less restrictive
[英]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.