使用POSIX提取git url的域

问题描述 投票:0回答:1

我正在尝试建立最强大的方法来从git存储库中提取域。对于网址:

ssh://[email protected]:22411/usage/project_100.git
git://example.org/path/to/repo.git
https://github.com/example/foobar.git
http://github.com/example/foobar.git
ssh://[email protected]/path/to/repo.git
git://host.com/path/to/repo.git

我可以使用:

echo $url | awk -F[/:] '{print $4}'

但是对于像这样的仓库:

"[email protected]:User/UserRepo.git"

这是行不通的。但是以下内容可以:

echo $url | awk -v FS="(@|:)" '{print $2}'

是否有某种可靠的方法可以使我始终在POSIX中吸引域?

bash git posix
1个回答
0
投票

您可以轻松地通过sed进行此操作。

© www.soinside.com 2019 - 2024. All rights reserved.