This is my current code. I am trying to replace a filename string in the file with another filename. But I am currently getting the error
"sed: 1: "s/directory = "[A-Za-z0 ...": bad flag in substitute command: 'U'"
What is wrong with this code?
function restart_existing ()
{
old="directory = \"[A-Za-z0-9\/]\""
new="directory = \"$1\""
sed -i '' "s/$old/$new/" "$HOME/angelpretendconfig"
}
restart_existing "$HOME/blahblahblah/shoot/blah"
EDIT: Thanks! I've adopted your advice, and adapted the code.
function restart_existing ()
{
old="directory = \"*\""
printf -v new 'directory = "%s"' "$1"
sed -i '' "s;$old;$new;" "$HOME/angelpretendconfig"
}
restart_existing "Query"
But now the line in question goes from
directory = "/home/jamie/bump/server"
directory = "Query"/home/jamie/bump/server"
Why does this occur?