Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run bash script from Windows PowerShell

In cygwin, I could just do ./script.sh args, but this opens the script file in notepad in PowerShell.

What do I need to do have it execute?

like image 576
wsorenson Avatar asked Jul 08 '09 15:07

wsorenson


People also ask

How do I run a Bash script in Windows PowerShell?

BASH will be available in the Command Prompt and PowerShell. Open Command Prompt and navigate to the folder where the script file is available. Type Bash script-filename.sh and hit the enter key. It will execute the script, and depending on the file, you should see an output.

Can I use Bash on Windows PowerShell?

Use bash: Right-click Start menu > select Windows PowerShell (Admin) > type "bash" > press Enter.

How do I run Bash on Windows?

Press Windows key + X then click Command prompt, at the command prompt, type: bash then hit Enter. If you want to be able to access the local file system, press Windows key + X, Command Prompt (Admin) then type bash at the prompt.

Can we run .sh file in Windows?

A . SH file is very similar to the batch file of the Windows operating system and can be run in the Linux-based operating system. It is also possible to run . SH file in Windows 10 using Windows Subsystem for Linux.


2 Answers

There is now a "native" solution on Windows 10, after enabling Bash on Windows, you can enter Bash shell by typing bash: Bash on Windows

You can run Bash script like bash ./script.sh, but keep in mind that C drive is located at /mnt/c, and external hard drives are not mountable. So you might need to change your script a bit so it is compatible to Windows.

Also, even as root, you can still get permission denied when moving files around in /mnt, but you have your full root power in the / file system.

Also make sure your shell script is formatted with Unix style, or there can be errors. Example script

like image 199
Marius Tancredi Avatar answered Sep 19 '22 00:09

Marius Tancredi


You should put the script as argument for a *NIX shell you run, equivalent to the *NIXish

sh myscriptfile 
like image 28
TheBonsai Avatar answered Sep 20 '22 00:09

TheBonsai