Written for macOS 10.14 (Mojave). The approach still works, but check the PPD key names for your printer.

Our student users don’t have admin rights, so the printer’s PPD file had to be adapted: DefaultAPOptionalDuplexer from False to True.

The trick is an in-place sed:

sed -i '' 's/*search_string/*replace_string/g' /path/to/file.extension

-i '' writes the change back into the same file (on macOS there is a space between -i and the empty quotes).

# change duplex
Printer_X=$(grep "*DefaultAPOptionalDuplexer: False" /private/etc/cups/ppd/Printer_X.ppd)

if [ "$Printer_X" == "*DefaultAPOptionalDuplexer: False" ]; then
    echo "change Printer_X to duplex"
    sed -i '' 's/*DefaultAPOptionalDuplexer: False/*DefaultAPOptionalDuplexer: True/g' /private/etc/cups/ppd/Printer_X.ppd
else
    echo "not needed"
fi

Originally published on anyresearch.net. These are notes from real-world admin work – test before you use them in production.