I'm making a bash script. My custom bashrc, to be more precise. And I need to have separate configs, depending on what "Linux" I am in (the Windows 10 Linux subsystem or actual Linux).
How can I tell them apart?
Things I tried:
$OSTYPE
- both return linux-gnu
uname -a
- both return similar Linux COMPUTER_NAME_HERE 3.4.0+ #1
PREEMPT Thu Aug 1 17:06:05 CST 2013 x86_64 x86_64 x86_64 GNU/Linux
lsb_release -a
- both return ubuntu xx.xx
cat /etc/issue.net
- both return Ubuntu 14.04.4 LTS
ld -v
- both return GNU ld (GNU Binutils for Ubuntu) 2.24
The only way I have found to make this work is to set some specific username for the Windows sub-system, and use $USER
, but that is not an option I'm willing to use. I need this to work out of the box, without custom user names, environment variables, etc..
See /proc/sys/kernel/osrelease
You can check for Windows with grep -qi Microsoft /proc/sys/kernel/osrelease 2> /dev/null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With