How to check if a program is run in Bash on Ubuntu on Windows and not just plain Ubuntu?

后端 未结 10 604
时光说笑
时光说笑 2020-12-05 02:07

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

10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-05 02:32

    I needed to test for macOS in addition to Windows Subsystem for Linux 2.

    This is the simplest thing working for us.

    if [[ $OSTYPE == darwin* ]]; then
      # macOS
    elif [[ "$(

    NOTE: The if order matters. On macOS you get this error when looking at proc/version.
    /proc/version: No such file or directory


    hat-tip @Niklas Holm and @Marc Cornellà in the top answer's comments for aiming me toward the correct WSL check.

提交回复
热议问题