1

Currently using the following and would like to remove the > /dev/null part.

cat << "EOF" | sudo tee /etc/pf.conf > /dev/null
EOF

For reference, the following throws an error.

zsh: permission denied: /etc/pf.anchors/local.test

sudo cat << "EOF" > /etc/pf.anchors/local.test
echo "Hello world"
EOF
sunknudsen
  • 5,128
  • 1
  • 27
  • 51

1 Answers1

1

You can start a new shell with root rights and redirect inside it:

sudo sh -c 'cat > "$1"' -- /etc/pf.conf

or shorter:

sudo sh -c 'cat > "$0"' /etc/pf.conf
sudo sh -c 'cat>"$0"' /etc/pf.conf

Use awk with redirection:

sudo awk -vf=/etc/pf.conf '{print > f}'
KamilCuk
  • 96,430
  • 6
  • 33
  • 74