Redirecting stdout with sudo: Why > fails and how to fix it
When you try to redirect output from a sudo command to a file using >, you’ll hit a permission error: $ sudo echo “echo hello” > /usr/local/bin/hello bash: /usr/local/bin/hello: Permission denied This happens because the shell processes the redirection operator > before sudo runs. The redirection happens in your unprivileged shell context, not as root….
