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

后端 未结 10 639
时光说笑
时光说笑 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:37

    Updating answer by @per-lundberg:

    if [[ ! -z "$IS_WSL" && ! -z "$WSL_DISTRO_NAME" ]]; then
        echo "You are not in wsl!"
    else
        echo "You are in wsl!"
    fi
    

    Note: IS_WSL existed in older verion while WSL_DISTRO_NAME exist in current version.

提交回复
热议问题