It is OK to use sudo
on a single command to run it with superuser privileges:
sudo echo "hi"
But when I use pipes with the command:
sudo echo "hi" > /a.txt
The superuser privilege does not extend to the pipe (> /a.txt
) part, and I get an error for denied permission:
bash: /a.txt: Permission denied
My question is:
Is there a syntax in which I can extend the scope of sudo
in above to also work on the pipeline part?