`sudo echo 'vm.swappiness=10' > /etc/sysctl.d/99-tuning.conf` fails with `bash: /etc/sysctl.d/99-tuning.conf: Permission denied`.
BeginnerTroubleshootingTroubleshooting: tools, portability, permissions and environment
Answer
Likely causes → The redirection is performed by your shell, as your user, before sudo runs. Only echo gets root privileges.
Diagnose → The error comes from bash:, not from sudo or echo, which shows the shell opened the file.
Fix → Let a privileged process open the file:
echo 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-tuning.conf > /dev/null
echo 'extra=1' | sudo tee -a /etc/app.conf > /dev/null # append
sudo install -m 0644 -o root -g root tuning.conf /etc/sysctl.d/99-tuning.conf
Prevent → Use sudo tee or install in scripts; better still, run the whole provisioning script as root once rather than sprinkling sudo.
More on Troubleshooting: tools, portability, permissions and environment
On a Mac, `sed -i 's/replicas: 2/replicas: 3/' deploy.yaml` fails with `sed: 1: "deploy.yaml": extra characters at the end of d command`.BeginnerA cleanup script fails on a developer's Mac with `date: illegal option -- d`.BeginnerA script that works on Ubuntu fails in an Alpine-based CI image with `grep: unrecognized option: P`.IntermediateAn `awk` one-liner works on your RHEL box but fails on Ubuntu with `awk: line 1: function gensub never defined`.Intermediate`comm -23 expected.txt installed.txt` prints `comm: file 1 is not in sorted order`, even though both files were produced with `sort`.Intermediate`grep ERROR /var/log/app/app.log` prints only `grep: /var/log/app/app.log: binary file matches`.Beginner