[英]expr / awk / sed: get git directory name from repo URL
Using bash expr , sed or awk , how can I determine the git base directory for a given git repo? 使用bash expr , sed或awk ,如何确定给定git repo的git基本目录?
For example: git@git.gitweb.com:/myModule-repo.git => myModule-repo 例如: git@git.gitweb.com:/myModule-repo.git => myModule-repo
If you insist on doing that with these tools, 如果您坚持使用这些工具进行操作,
echo git@git.gitweb.com:/myModule-repo.git | sed 's%^.*/\([^/]*\)\.git$%\1%g'
(find the substring from the last / until the literary .git) should do the trick, otherwise I would use (从最后一个/直到文学.git中找到子字符串)应该可以解决问题,否则我会使用
basename git@git.gitweb.com:/myModule-repo.git .git
which does the same (also, it is much more transparent and basename
is as POSIX as sed
and awk
). 这样做是一样的(同样,它更加透明,并且基basename
与sed
和awk
一样与POSIX一样)。
echo "git@git.gitweb.com:/myModule-repo.git" | sed 's|git@git.gitweb.com:/||;s/.git//'
echo git@git.gitweb.com:/myModule-repo.git | awk 'BEGIN {FS="/"} {print substr ($2, 1, 13)}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.