※2022年1月10日 現在では非推奨です
結論
apt-get dist-upgrade
の場合です
$ DEBIAN_FRONTEND=noninteractive sudo -E apt-get dist-upgrade -y
状況
grub-pc
などで以下のような画面が出て対話が必要なときがあります。これを避けたい場合です。
根拠
$ man sudo (前略) -E, --preserve-env Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment. (後略)
補足
Ubuntu 16.04
以降が対象だと思います。