Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions env-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,18 @@ function replace_in_conf() {
val=$2
path=$3

old="$key"=".*"
new="$key"="$val"
# Escape special characters in the replacement string
escaped=$(echo "$val" | sed 's/[&/\]/\\&/g')

if [ -z "$(grep "$old" $path)" ]
then
old="$key=.*"
new="$key=$escaped"

if ! grep -q "^$key=" "$path"; then
# Add value
echo $new >> $path
echo "$new" >> "$path"
else
# Value exists in conf
sudo sed -i "s/$old/$new/g" $path
# Replace existing value safely
sudo sed -i "s|^$old|$new|" "$path"
fi
}

Expand Down