I am trying to use the sed
command to edit a value in the .git/config
file. When running the remote origin command, the config file creates the line of text like this":
url = https://github.com/abbatrombone/testprj
The name changes based on the username abbatrombone
and project name testprj
. I am trying to edit this so it contains the key value so I can commit via the terminal rather than have to go in and edit it.
It would look something like this:
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;
I have tried using double quotes over single quotes so variables expand properly, changing the delimiter to |
from /
and doing ${var}
rather than $var
.
How do I get the sed command to update this string correctly?
sed -i "s|${filepath}|${correctfilepath}|g" $Dir/.git/config
file/path
notfile|path
the reason i was using|
is because from my understanding the character after s is the delimiter.sed -i "s|${filepath}/${correctfilepath}|g" $Dir/.git/config
. In this command, the delimiter|
only appears twice. I believe the delimiter needs to occur three times.