我正在尝试使用该sed
命令编辑.git/config
文件中的值。运行远程源命令时,配置文件会创建如下文本行”:
url = https://github.com/abbatrombone/testprj
名称根据用户名abbatrombone
和项目名称而变化testprj
。我正在尝试编辑它,使其包含键值,这样我就可以通过终端提交,而不必进入并编辑它。它看起来像这样:
url = https://[email protected]/abbatrombone/testprj.git
echo "paste you github key. Make sure it has the correct permissions"
read -r gitkey
echo "Username"
read -r username
echo "projectname"
read -r projectname
filepath="url = https://github.com/$username/$projectname"
correctfilepath="url = https://[email protected]/$username/$projectname.git"
git remote add origin https://github.com/"$username"/"$projectname"
sed -i "s|${filepath}/${correctfilepath}|g" $Dir/.git/config
git remote add origin main https://github.com/"$username"/"$projectname"; # first time updates git 2nd time runs it correctly
git push -u origin main;
我尝试使用双引号而不是单引号,以便变量正确扩展,将分隔符更改为|
from/
并执行${var}
而不是$var
。
我如何让 sed 命令正确更新这个字符串?