Interview Prep/Shell Scripting/Arguments, I/O, here-docs, process substitution and subshells

What does `tee` do and how do you write to a root-owned file with `sudo`?

IntermediateConceptArguments, I/O, here-docs, process substitution and subshells
Answer

tee copies stdin to stdout and to one or more files (-a appends). sudo echo x > /etc/file fails because the redirection is done by your unprivileged shell, not by sudo.

echo 'vm.max_map_count=262144' | sudo tee /etc/sysctl.d/99-es.conf >/dev/null
sudo tee -a /etc/hosts >/dev/null <<'EOF'
10.0.1.10 db.internal
EOF
All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Arguments, I/O, here-docs, process substitution and subshells