I created a sed function to escape slashes.
sed_replace_word() {
var_1_clean=$(echo "$1" | sed 's/\//\\\//g')
var_2_clean=$(echo "$2" | sed 's/\//\\\//g')
sed -i "s/$var_1_clean/$var_2_clean/g" $3
}
When I'm now calling the function, he doesn't use the variables, because they need to set in single quotes:
sed_replace_word "^EXT_IF=.*" "EXT_IF="${INTERFACE}"" "/etc/arno-iptables-firewall/firewall.conf"
The Output of that example should be:
EXT_IF="eth0"
Is it possible to set single quotes (or to make the script use the variables), without setting the ' single quotes manually? Maybe an option to set them in the function, if there is a variable "detected".
Yes, I want to call a function and the parameter I'm giving to the function may contain a variable.
The content of that variable should be available in that function. So ${INTERFACE} (which contains eth0 for exmaple) should be in var_2_clean.
Example:
INTERFACE="eth0"
Calling function (shortended):
sed_replace_word "EXT_IF=another_content + ${INTERFACE}"
Result at the end of the function it should do:
sed -i "s/$var_1_clean/EXT_IF=another_content + eth0/g" $3