FYI - I just came across this same error message when using RetroPie Setup on my Raspberry Pi 4. It turns out, I was running it via sudo, while already in a sudo shell. To reproduce, do the following:

sudo -s cd /home/pi/RetroPie-Setup sudo ./retropie_setup.sh

To fix, either just exit out of the sudo shell, or don't use sudo to run RetroPie while already in a sudo shell.

Hope this helps.

- George