-2
echo -n  "Username: "
read usernamert
echo -n "Password: "
read passwordt
echo -n "IP: "
read IPt
echo -n  "Channel: "
read channelt

t1=$(echo "www://$usernamet:$passwordt@$IPt/TEST/SOMETHING?channel=$channelt1&TRUE=1")

sed -i "s+"t_1", "t_2"+"$t1", "AAA"+g" test.txt

link should looks like www://username:password@$1.1.1.1/TEST/SOMETHING?channel=2&TRUE=1

so this kind of link i want to change with string in file test.txt

"t_1", "t_2"

but allways gets error. Where I mistake? I also tried to put variables in "" inside t1 variable, but didnt help.

Barmar
  • 741,623
  • 53
  • 500
  • 612
Jason D
  • 3
  • 2
  • If you need to match `"` literally, you need to escape it: `\"` – Barmar Oct 01 '21 at 21:04
  • when i add that escape ONLY with " and echo it i get this(with all user inputs) "www://username:password@$1.1.1.1/TEST/SOMETHING?channel=2&TRUE=1" and i uncomment sed command to test it, and there is no errors, but when cat file, it still exist this string "t_1", "t_2", instead of that www..... – Jason D Oct 01 '21 at 21:07
  • It's easier if you use single quotes: `sed 's+"t_1", "t_2"+"'"$t1"'", "AAA"+g'` – Barmar Oct 01 '21 at 21:10
  • Just switch to double quotes around the variable. – Barmar Oct 01 '21 at 21:10

1 Answers1

0

Your double quotes are delimiting the shell strings, not being used literally in the sed pattern and replacement.

Put single quotes around the sed operation, except for the variable.

sed -i 's+"t_1", "t_2"+"'"$t1"'", "AAA"+g' test.txt
Barmar
  • 741,623
  • 53
  • 500
  • 612