I have to run this command sudo sh -c "echo 'nameserver 8.8.8.8' >> /etc/resolv.conf"
to append a line nameserver 8.8.8.8
into /etc/resolv.conf
file. I know, it could be possible only through subshell.
My questions:
Is that it could be possible without running the command in subshell?
On which cases, a command should be runned in subshell?
sudo sh -c ...
doesn't create a subshell, but a new shell process (and you don't need this new shell as long as you can usesed
ortee
or something else instead of>>
). And>>
is not a real command to usesudo
on it, but is an redirection operator. So, your question doesn't have sense, or logic... – Radu Rădeanu May 30 '14 at 10:40