I wanted to create a .bashrc
function
that would simplify passing data to a write-protected file.
function pipe {
sudo bash -c "$1"
}
Unfortunately the command
pipe echo something > /etc/importantfile
still shows me that permission is denied. How should I fix it?
/etc/importantfile
is the "restricted" one, you get the error because the shell tries to write to it when callingpipe echo something > /etc/importantfile
(and not inside the function). Also note that you are passing two arguments to your function, but are only using the first one. – Janis Mar 15 '15 at 14:24sudo
redirect stdout …?; also How do I use redirection withsudo
?, Redirecting stdout to a file you don’t have write permission on, and/or Why do I get “Permission denied” when redirecting the output ofsudo
?. – G-Man Says 'Reinstate Monica' Mar 15 '15 at 16:23