fixed bash-for-windows

This commit is contained in:
Cametendo
2026-05-31 21:49:13 +02:00
parent 7b3a101946
commit 9037606447
8 changed files with 437 additions and 123 deletions

View File

@@ -68,6 +68,42 @@ bash script.sh # run a script file
bash script.sh arg1 # pass arguments ($1, $2, ...)
```
### Running bash scripts
Any file with a `#!/usr/bin/env bash` or `#!/bin/bash` shebang is automatically detected and executed through bash-for-windows — no need to invoke `bash` explicitly.
**Run by passing the path directly:**
```powershell
bash myscript.sh
bash myscript # extension is optional
bash C:\scripts\deploy.sh production
```
**Or put the script on PATH and call it by name:**
If the script is in a directory that is on your `PATH` (e.g. the bash-for-windows install directory), you can call it directly from the interactive shell or from PowerShell:
```
waifufetch
waifu
deploy
```
Bash-for-windows detects the shebang, runs the script through its own interpreter, and passes any arguments as `$1`, `$2`, etc.
**CRLF line endings are handled automatically.** Scripts checked out on Windows often have `\r\n` line endings. Bash-for-windows strips the carriage returns before executing, so `#!/usr/bin/env bash\r` in the shebang line never causes the `env: 'bash\r': No such file or directory` error you get with WSL.
**Adding a script to PATH:**
The easiest place to drop scripts is the same directory bash-for-windows is installed in:
```powershell
$d = "$env:LOCALAPPDATA\Programs\BashForWindows"
Copy-Item .\myscript $d\myscript
```
That directory is already on `PATH` after running `install.ps1`, so the script is immediately callable from any shell.
### Examples
```bash