0

I am using a command that determines my active network interface with internet connection with netiface=$(ip route get 8.8.8.8 | sed -n 's/.*dev \([^\ ]*\).*/\1/p') where netiface is the variable with the network interface assigned to it.

I need the results of that command (the variable) to be added to a system file and my line for this is where the command searches for that line and adds what I need:

sed -i 's/systemd-networkd-wait-online/systemd-networkd-wait-online --interface=$netiface/' /lib/systemd/system/systemd-networkd-wait-online.service

The ending results of that line should look like:

systemd-networkd-wait-online --interface=eth0

Now all of this works if I enter single command entries at the command line but if I run these 2 commands inside of a script, I end up with --interface=$netiface where it is printing the variable name itself and not the interface name itself. Hopefully this makes sense. Where am I going wrong where when the second line is executed it is only printing the variable name, not the variable results. It is as if the variable is not being stored to where it is not available for the sed line to use.

muru
  • 207,228

0 Answers0