I'd like to replace a string within a variable, e.g.:
Test=Today, 12:34
I'd like to replace the "Today" within the variable Test with a Date variable I declared before.
I tried using the sed command:
sed -i -e "s/Today/$Date" '$Test'
But it would just print out an error and the file '$Test' is not known. Is using sed only possible with text files?
$Testis not a file. You can use:sed '....' <<< "$Test"or better do it in bash itself using"${Test/Today/$Date}"$Testor put it in double-quotes"$Test". If you use single quotes it will be treated as a string literal."${Test/Today/$Date}"isn't a command, it's an expression that produces a string. You need to do something with that string, like set a variable to it (Test="${Test/Today/$Date}"would replace the current value ofTestwith the modified version), print it (echo "${Test/Today/$Date}"), or something like that.