The variable $^O (that's a capital 'O', not a zero) holds the name of the operating system.
Depending on what you want, it may or may not give the answer you want - on my system it gives 'linux' without saying which distro. I'm not so sure about what it says on Windows or MacOS.