Bash – set variable with or without export are different

I am working on an AWS ec2 instance provisioning script today. I am using Packer to provision the instance and build an AMI. The instance is running Ubuntu. There is a very annoying error when I am using ‘apt-get -y upgrade’ or ‘apt-get -y install’:

debconf: unable to initialize frontend: Dialog
debconf: (Dialog frontend will not work on a dumb terminal, an emacs shell buffer, or without a controlling terminal.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (This frontend requires a controlling tty.)
debconf: falling back to frontend: Teletype
dpkg-preconfigure: unable to re-open stdin:

Google it and not hard to find the fix is to add “DEBIAN_FRONTEND=noninteractive” in your script
(credit to link to stackoverflow)

However, it still doesn’t work for me until I realize I need to put in ‘export’:

export DEBIAN_FRONTEND=noninteractive

Apparently ‘export’ will make the variable is available to any process you run from your current shell process (not parent process though). Without ‘export’, the variable scope is restricted to the shell, and is not available to any other process.
(credit to link to stackoverflow)