Pretty straightforward, the usual places to figure out the OS you\'re on seem to be identical to plain Ubuntu on Ubuntu for Windows. For example uname -a is ide
For WSL2, we can no longer detect through kernel version because it is running an actual Linux kernel in Hyper-V. However, it still can call explorer.exe existing in every Windows installation. So we could...
if [ -x "$(command -v explorer.exe)" ]; then
echo "We are running on WSL"
fi
This should be a more generic way to detect if the script is running on WSL.
Edit: See answers above. I forgot to count Unix-like environments like Msys2 in.