You can try spamming ALT + F4, at least this worked for me in Kali, where I had no GUI, only terminal.
To avoid such softlocks in the future, make sure you run your scripts in the background with the "&" command at the end of the script execution command. Even better, the infinite loop part of your script could be a separate function which is called in the background inside your script. Also note that, the termination of the background scripts should be handled as well.
Now, in order to run scripts at boot, you could try adding it to the .bashrc file located in your home folder.
For example:
./myscript.sh &
If you want the script to run once and only once, independently from the user, you need to add it to /etc/rc.local. That is because the .bashrc file is user specific and runs again when a new bash shell is spawned for this user. There is an official guide from raspberry pi site here : https://www.raspberrypi.org/documentation/linux/usage/rc-local.md