我有串gitproject使字符串的網址 - sed?
如何使用SED命令gitproject參數爲了做到:
http://user_name:[email protected]/gitproject.git
http://example.com/gitproject.git
BR
我有串gitproject使字符串的網址 - sed?
如何使用SED命令gitproject參數爲了做到:
http://user_name:[email protected]/gitproject.git
http://example.com/gitproject.git
BR
可以使用${VARIABLE_NAME}
syntax擴大shell變量沒有任何一方添加任何多餘的空格,如:
proj=gitproject
echo http://[email protected]/${proj}.git
echo http://example.com/${proj}.git
無需sed的:
str="gitproject"
echo "http://user_name:[email protected]/${str}.git"
echo "http://example.com/${str}.git"
至於問,該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