If the accepted solution causes your script to crash (this happened to me with a python script), you can completely remove the DISPLAY variable using the bash command unset. That is, unset DISPLAY.
unset DISPLAY
https://stackoverflow.com/questions/19930715/how-to-undo-display-export-in-linux