Issue
I'm trying to modify a variable in a script with sed
.
The variable is a reference to a path that I want to modify.
Is it possible to use sed
in a file which modifies this script for the next time it's launched?
I tried:
#!/bin/bash
main () {
newdir="/okl/dfsdf/dfsf/"
sed -i "s|mnt="/*/"|mnt="\$newdir"|g" file
}
main
I expected the mnt
variable to change but only the first time it is defined in the code, that's why I need to double quote mnt="/*/"
.
Solution
It looks like you want to change a line like
mnt=/some/path/file
with
mnt=/okl/dfsdf/dfsf/file
You can use
newdir="/okl/dfsdf/dfsf/"
sed -i 's|mnt=.*/|mnt='$newdir'|' file
Answered By - Walter A Answer Checked By - David Marino (WPSolving Volunteer)