Insert a user input string after matched string in file

i am having file like this

#!/bin/bash

read -p 'Username: ' uservar
match='<color="red" />'


text='this is only a test
so please be patient
<color="red" />'

echo "$text" | sed "s/$match/&$uservar\g"

so desireble output what i want is if user type MARIA

this is only a test
so please be patient
<color="red" />
MARIA

when try to execute it returns me

sed: -e expression #1, char 32: unknown option to `s'

Where is a mistake, i couldnt find it.
It is working with "simple" words like PATIENT or some else, only dont work with this tags.

match='<color="red" />' contains a forward slash (/) which when expanded for the search it messes up with the parsing in sed.
Possible solutions:
Escape the offending character in the var

match='<color="red" \/>'

Or change the search/replace delimiter characters to something else

sed "s#$match#&$uservar#g"

By the way, the backslash before pattern flag g is not correct, it should be a forward slash /g and I do not see any reason for it to exist, in this case.

Thanks.
Idea behind all this is to read user input in numbers from 4-8, and each number present a different html tag and with more options.
So if user input is 6, it will added 4,5 and 6 after $match string.

------ Post updated at 03:07 AM ------

But now for the test purposes i wanted to put maria if user input 1, but i cant, why?

case $uservar in
  1) echo "$text" | sed "s/$match/&MARIA/" ;;
  2) echo -e "\nYou are 2" ;;
  *) echo dont know ;;
esac

it returns me just my $text variable

Again, may depend on the contents of $match . What's it?

#!/bin/bash

read -p 'Enter number [1-8]: ' uservar
match='<color="red" \/>'

text='this is only a test
so please be patient
<color="red" />'

echo "$text" | sed "s/$match/&\n$uservar/"

------ Post updated at 04:04 AM ------

I will deal with cases and echo (just for test, idea is to put into file) to see results

#case $uservar in
 # 1) echo "$text" | sed "s/$match/&$uservar/" ;;
 # 2) echo -e "\nYou are 2" ;;
 # *) echo dont know ;;
#esac

Where exactly is the problem?

this is only a test
so please be patient
<color="red" />MARIA

because when user input 1 it prints me only

MARIA is not printed.

case $uservar in
  1) echo "$text" | sed "s/$match/&MARIA/" ;;
  2) echo -e "\nYou are 2" ;;
  *) echo dont know ;;
esac
read -p 'Enter number [1-8]: ' uservar

------ Post updated at 04:24 AM ------

Sorry my mistake, my match string is not match within text, its because i tested it 1000 times.
SORRY!

I am having one maybe stupid questions.
Does it possible to merge cases?

so for example, if user input is 1 it print

MARIA

, if input 2, it print

MARIA
HELEN

is user input is 3 it print

MARIA
HELEN
JOHN

So this data is more complicated and long and I dont wanna to give that in cases, so if user input is 2, i dont want to echo

I want something case1\nHELEN
and so on..

Unclear. I don't know what

should be.

If I enter 2 for uservar , this is what I get (after having adapted the case ... esac statement):

this is only a test
so please be patient
<color="red" />Helen

Idea is that i have multiple cases. Case 2 is case1 + some new string which i added.
Case 3 is case1+case2+some new string

------ Post updated at 05:06 AM ------

So if case one result is
123 text
Case2 will be
123 text new2
Case3 will be
123 text new2 new3

That's NOT suitable for a case statement; use an array and a for loop:

ARR1=( 0 text1 text2 text3 text4 text5 )
uservar=4
for (( i=1; i<=uservar; i++)); do echo  ${ARR1}; done
text1
text2
text3
text4

I will try to combine with user input and variable match and text ehich i said earlier

------ Post updated at 08:58 AM ------

i did it like this

#!/bin/bash
read -p 'Enter number:' new
match='<color="red"  \/>'
text='text='this is only a test
so please be patient
<color="red" />''

text0='<h1> <!-- COmment -->
this is a test
    </h1>'
text1="MARIA"
text2="JACK"
text3="BRAD"
ARR1=( 0 $text0 $text1 $text2 $text3 )
uservar=$new
for (( i=1; i<=uservar; i++)); do echo "$text" | sed "s/$match/&\n ${ARR1}/" ;done

So when execute it prints me only a

It should print me

------ Post updated at 08:58 AM ------

So - what do you expect? It prints exactly what you told it to print. Did you do a test run with nothing but my proposal, unalterd?

I dont know why dont print from var $text1, $text2 etc. Why only $text0

------ Post updated at 02:44 PM ------

I use for on my echo with sed..hmmm, i must to use for on array within sed, if I am correct...

anyone?