使用 bash expr , sed 或 awk ,如何确定给定git repo的git基目录?
例如: git@git.gitweb.com:/myModule-repo.git =>的 Mymodule中回购
答案 0 :(得分:5)
如果您坚持使用这些工具,
echo git@git.gitweb.com:/myModule-repo.git | sed 's%^.*/\([^/]*\)\.git$%\1%g'
(从最后一个/直到文学.git找到子串)应该做的伎俩,否则我会用
basename git@git.gitweb.com:/myModule-repo.git .git
执行相同的操作(同样,它更加透明,basename
与POSIX一样sed
和awk
)。
答案 1 :(得分:0)
echo "git@git.gitweb.com:/myModule-repo.git" | sed 's|git@git.gitweb.com:/||;s/.git//'
答案 2 :(得分:0)
echo git@git.gitweb.com:/myModule-repo.git | awk 'BEGIN {FS="/"} {print substr ($2, 1, 13)}'