2013-10-04 58 views

回答

2

無需sed的:

str="gitproject" 
echo "http://user_name:[email protected]/${str}.git" 
echo "http://example.com/${str}.git" 
0

至於問,該sed方式:

echo "http://user_name:[email protected]/gitproject.git" | 
    sed -e 's|//[^/]*/|//example.com/|' 
http://example.com/gitproject.git 

一個bash唯一的辦法現在:

gitproject="http://user_name:[email protected]/gitproject.git" 
proto=${gitproject%%//*} 
path=${gitproject#${proto}//*/} 
echo ${proto}//example.com/$path 
http://example.com/gitproject.git