linuxwindowsbashcmdwindows-subsystem-for-linux

How to run WSL bash functions from CMD


In Windows cmd you can run wsl commands just by typing:

> wsl pwd
/mnt/c/Users/user/

But when I try to run functions that are stored in ~/.bashrc file, nothing is happening:

> wsl test

>

While in wsl function is working fine:

> test
/mnt/c/Users/user/
>

Solution

  • It's probably because your.bashrc exits early when it's not started interactively. You will find something like this in the first lines.

    # If not running interactively, don't do anything
    case $- in
        *i*) ;;
          *) return;;
    esac
    

    I would recommend extracting the test function from .bashrc to a separate file.