How modify /etc/network/interfaces without gedit?
-
13-07-2021 - |
Question
I'm doing a script and I would like to add the following line
pre-up iptables-restore < /etc/iptables.rules
to the file interfaces which is located on /etc/network/interfaces,but although I have enabled the permissions to write in this file(I work in Ubuntu), I'm not able to do it... I'm trying to use the following command in my bash script
sudo echo "pre-up iptables-restore < /etc/iptables.rules" >> /etc/network/interfaces
Any suggestion of how to do it without using gedit o vi?
Thanks in advance!
Solution
You need to tell bash not to use redirection before it starts sudo:
sudo bash -c 'echo "pre-up iptables-restore < /etc/iptables.rules" >> /etc/network/interfaces'
this way the complete command will be executed with root access, not only the echo "pre-up iptables-restore < /etc/iptables.rules"
part
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow