Bash 从字符串生成url-sed?

Bash 从字符串生成url-sed?,bash,sed,Bash,Sed,我有一个项目 如何将sed命令与gitproject参数一起使用,以便执行以下操作: http://user_name:user_password@example.com/gitproject.git http://example.com/gitproject.git BR您可以使用展开shell变量,而无需在任何一侧添加任何额外的空格,例如: proj=gitproject echo http://user_name_userpassword@example.com/${proj}.git e

我有一个项目

如何将sed命令与gitproject参数一起使用,以便执行以下操作:

http://user_name:user_password@example.com/gitproject.git http://example.com/gitproject.git BR

您可以使用展开shell变量,而无需在任何一侧添加任何额外的空格,例如:

proj=gitproject
echo http://user_name_userpassword@example.com/${proj}.git
echo http://example.com/${proj}.git
不需要sed:

str="gitproject"
echo "http://user_name:user_password@example.com/${str}.git"
echo "http://example.com/${str}.git"
正如所问,sed的方式是:

bash现在唯一的方法是:

gitproject="http://user_name:user_password@example.com/gitproject.git"
proto=${gitproject%%//*}
path=${gitproject#${proto}//*/}
echo ${proto}//example.com/$path
http://example.com/gitproject.git
gitproject="http://user_name:user_password@example.com/gitproject.git"
proto=${gitproject%%//*}
path=${gitproject#${proto}//*/}
echo ${proto}//example.com/$path
http://example.com/gitproject.git