0

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/
>
8
  • Try wsl bash -c test Commented Jul 19 at 8:46
  • Still nothing, as before Commented Jul 19 at 8:56
  • 1
    @close: I can't see why this question is closed because of ` not about programming or software development.` Bash scripting is still programming. Otherwise, you could close many more questions. Commented Jul 19 at 10:56
  • 1
    Please read in bash manual the chapter 6.2 Bash Startup Files. The file ~/.bashrc is executed by bash only on being Invoked as an interactive non-login shell. That is not the case on running from Windows Command Prompt Windows Subsystem for Linux and execute a command like bash with the option -c to execute something by bash in the Linux environment. Commented Jul 19 at 10:57
  • 1
    BTW: test is a Bourne Shell Builtin command. It is not advisable to name a function test in any shell script file including .bashrc. Commented Jul 19 at 11:21

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I will put functions in separate .sh files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.