How to access WSL PATH from Powershell core? [duplicate] - bash

This question already has an answer here:
What is the difference between calling a command via "wsl [command]" and opening a wsl shell and calling "[command]"?
(1 answer)
Closed 1 year ago.
If I open up the Ubuntu app (terminal) and type echo $PATH, I get a bunch of directories. If I type wsl echo $PATH in Powershell core, I get absolutely nothing (a blank row). I would like to run a Linux command from Powershell core, how do I do that?

That's because the .bashrc isn't run when you just run wsl <command>, you need to run wsl bash -c '<command>', or run <command> while inside a bash shell.

Related

Why is $OSTYPE returning "linux-gnu" on Windows?

Problem
When I run a bash script on Windows:
bash my_script.sh
I get linux-gnu for $OSTYPE inside the script.
Why is this like this?
I assume that i have WSL installed is relevant here.
Tested in PowerShell and CMD.
Git bash is returning msys like expected! Thx #user1934428
Background
I want to start some python scripts from bash, but not inside WSL.
From my command line I reach different python versions on windows, but from inside the bash scripts it is using the one inside WSL (except for GitBash).
You're right, running the bash command in PowerShell or CMD will launch WSL to run your script. You confirm this (and see which version of WSL) by running cat /etc/issue in your bash script. Your WSL environment will have an independent set of environment variables (not just $OSTYPE). You can see this by comparing the output of Get-ChildItem -Path Env:\ in PowerShell to the output of env (after you launch bash from PowerShell).
I suspect that the python version discrepancy you're seeing is a result of the PATH variable in your WSL runtime not matching what you have set in your PowerShell environment. You can fix your version issue by setting an alias containing a path to the python executable you want to use by adding alias python=/c/path/to/python.exe to the start of your bash scripts.
Alternatively, you can use a tool like Cygwin or git-bash to run your scripts. I'm not sure if they will use the same path variables as Windows so you may need to set those manually too.

Use WSL(Windows Subsystem for Linux) bash command in CMD

I am favorite user of WSL.
Before Restoring my Windows 10 OS, I setup WSL in my Windows and I didn't change any configuration. But One Day, the bash command were executed in CMD immediately. So, If I opened CMD and run a command such as 'ls', then result was the same in bash thing.
However now, I restore my windows and above command excuting no longer occurs. I often use bash commands, so I want to execute bash command in CMD. What should I do?

How do i run url command from my terminal? [duplicate]

This question already has answers here:
Execute bash script from URL
(16 answers)
Closed 4 years ago.
I have commands for example like this:
git clone https://example.com/mygit.git && cd mygit && npm i
in a file that i uploaded to an url, I want to run it from terminal, how do I run it from my terminal?
Are you using a Linux distro or Windows?
Assuming its Linux - you need to have the file execute permission bit set ( see here for more information -> https://www.tutorialspoint.com/unix/unix-file-permission.htm )
Then you need to execute the file with the path specified ie. if the script is called "myScript.sh" you would run:
./myScript.sh
or
/path/to/myScript.sh

Bash command on cURL for Windows [duplicate]

This question already has answers here:
How to run .sh on Windows Command Prompt?
(11 answers)
Closed 5 years ago.
I want to install Hyperledger Fabric to build blockchain apps and the documentation tells me to run a bash command to extract platform-specific binaries.
http://hyperledger-fabric.readthedocs.io/en/release/samples.html#binaries
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/v1.0.5/scripts/bootstrap.sh | bash -s 1.0.5
And to this, Terminal outputs:
'bash' is not recognized as an internal or external command, operable program or batch file.
What's the problem I'm facing? I'm running cURL version:
curl 7.58.0 (x86_64-pc-win32) libcurl/7.58.0 OpenSSL/1.1.0g (WinSSL) zlib/1.2.11 WinIDN libssh2/1.8.0 nghttp2/1.30.0
PS: Already installed curl into environment variables.
The command you pasted pipes all its output to a program called bash. This is not a standard program for windows.
As stated on the website you've linked:
If you are running on Windows you will want to make use of the Docker Quickstart Terminal for the upcoming terminal commands. Please visit the Prerequisites if you haven’t previously installed it.
So... use the Quickstart Terminal and read about the Prerequisites first?

vim - run :!commands in my .bashrc [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Commands executed from vim are not recognizing bash command aliases
Why doesn't my vim know my alias?
say I set
alias kapow='grep'
in my .bashrc, which I source after.
I open vim, type
:!kapow "dude"
but vim tries to run /bin/bash kapow, when I actually wanted it to run my alias.
How does one run commands from a bashrc inside of vim (without leaving to the :shell)?
The vim manual says this about :!
On Unix the command normally runs in a non-interactive shell. If you want an interactive shell to be used (to use aliases) set 'shellcmdflag' to "-ic".

Resources