sed - How to replace right part of equal sign (=) on a line

Hello.

Using a bash script , I have a variable name for the file I want to modify

FILE_TO_EDIT="/etc/my_config_file"

And I have a variable name for the parameter to change

PARAMETER="fallback_node"
PARAMETER_NEW_VALUE="http://my_server_name.com/new_path" 

A config file may contain :

1�) just and only just :

# fallback_node = http://example.com/path/to/sync

or 2�) just and only just :

fallback_node = http://my_server_name.com/some_web

In case 1 just add

"$PARAMETER = $PARAMETER_NEW_VALUE" 

just under the commented line

In case 2
a) just replace the right part of the equal sign with $PARAMETER_NEW_VALUE
or
b) comment out the ligne and add a new ligne with. "$PARAMETER = $PARAMETER_NEW_VALUE"

Any help is welcome

You could try this. Make sure the variables are sed-safe though..

sed "s;^[# ]*\(${PARAMETER} * = *\)\(.*\);# \1\2\n\1${PARAMETER_NEW_VALUE};" "${FILE_TO_EDIT}"

Should be great if you can explain the syntax for my learning.

Any way I will try this.

---------- Post updated at 19:57 ---------- Previous update was at 14:00 ----------

Small bug.

Parameters :

PARAMETER="fallback_node"
PARAMETER_NEW_VALUE="http://localhost/FF_DB"

Initial data in config file :

[nodes]
# You must set this to your client-visible server URL.
# fallback_node = http://example.com/path/to/sync

Data after running sed command :

[nodes]
# You must set this to your client-visible server URL.
# fallback_node = http://example.com/path/to/sync
fallback_node = http://localhost/FF_DB

Good.
Now editing the config file with some other data and we get :

[nodes]
# You must set this to your client-visible server URL.
# fallback_node = http://example.com/path/to/sync
fallback_node = http://localhost/OTHER_TEST

Data after running sed command :

[nodes]
# You must set this to your client-visible server URL.
# fallback_node = http://example.com/path/to/sync
fallback_node = http://localhost/FF_DB
# fallback_node = http://localhost/OTHER_TEST
fallback_node = http://localhost/FF_DB

Something like :
1�) Add new line with new parameter after the 1st line which is commeted out when token is encounted
2�) comment out line with actual parameter the 1st line which is not commeted out when token is encounted
3�)1�) Add new line with new parameter after the next line which is commeted out when token is encounted

Any help is welcome