0

If i'm understanding some of these heredoc tutorials properly, you can redirect with a heredoc like this

Using Stdout of sudo -u

sudo -u someuser -c bash <<EOF
{
  foo
  bar
} >> /tmp/somefile.txt
EOF

and like this, redirecting stdin

sudo -u someuser -c cat <<EOF >/tmp/somefile.txt
foo
bar
EOF

Is there a benefit to one over the other? Am I understanding this correctly?

ruevaughn
  • 1,289
  • 1
  • 17
  • 46
  • 1
    The former switches to the privileged account before creating the file, so it will be owned by the user you switched to. Regular redirections are handled by your current shell, as yourself. This is almost certainly a duplicate. – tripleee Nov 30 '21 at 12:14

0 Answers0