Dialog is a really useful utility for creating professional looking dialog boxes and menus within a shell script. I'm working on a boot-time script that allows the user to make system-level changes before the system has fully booted.
When testing my script from the command line, the dialog menu looked fine. However, whenever I set the script to start during boot (
update-rc.d myscript.sh defaults, on Debian-based systems) here is what the menu looked like:
UGH! It was barely usable. At first, I thought this would be an endlessly difficult problem to solve given my limited in-depth knowledge of Linux (I'm getting there!), but then I realized the main difference between the script running during boot and the script running after I had logged in was that my environment variables had not been loaded.
From the command line, I ran the
env command to display all my current environment variables:
debian_vm:~# env TERM=xterm-color SHELL=/bin/bash SSH_CLIENT=172.16.168.1 61315 22 SSH_TTY=/dev/pts/0 USER=root MAIL=/var/mail/root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11 PWD=/root LANG=en_US.UTF-8 PS1=h:w$ SHLVL=1 HOME=/root LANGUAGE=en_US:en_GB:en LOGNAME=root SSH_CONNECTION=172.16.168.1 61315 172.16.168.132 22 _=/usr/bin/env
The three variables that caught my eye were TERM, SHELL, and LANG. After a little trial and error, I discovered setting the LANG variable fixed the display issues with dialog! I added the following near the top of my script:
Now when my script loads during boot, everything looks correct: