我正在尝试建立最强大的方法来从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中吸引域?
您可以轻松地通过sed
进行此操作。