Detecting if you are on WSL system

What’s the best way to detect if you are into a WSL environement?

https://github.com/Microsoft/WSL/issues/423 has some discussion about that and suggests looking if /proc/sys/kernel/osrelease or /proc/version contains “microsoft”

That feels a bit hackish and might stop working if some WSL instance decides to use a custom kernel?

Does anyone know of a better way?

This is what snapd is doing https://github.com/snapcore/snapd/blob/master/release/release.go#L116

1 Like

Thanks @sergiusens, I’ve seen a few example of people doing that now so it seems the “most standard way” today…