diff --git a/.vuepress/configs/sidebar/en.ts b/.vuepress/configs/sidebar/en.ts index aefc4ddbddb..3a2b3284420 100644 --- a/.vuepress/configs/sidebar/en.ts +++ b/.vuepress/configs/sidebar/en.ts @@ -93,6 +93,7 @@ export const sidebarEn: SidebarConfig = { children: [ '/book/coming_from_bash.md', '/book/coming_from_cmd.md', + '/book/coming_from_powershell.md', '/book/nushell_map.md', '/book/nushell_map_imperative.md', '/book/nushell_map_functional.md', diff --git a/book/coming_from_powershell.md b/book/coming_from_powershell.md new file mode 100644 index 00000000000..7d50f434827 --- /dev/null +++ b/book/coming_from_powershell.md @@ -0,0 +1,67 @@ +# Coming from PowerShell + +::: tip +PowerShell pipelines pass rich **.NET objects**, which allow property access like `$process.Name` or piping objects directly into cmdlets that understand them. + +Nushell pipelines, by contrast, pass **structured data** such as tables, lists, and values. +This means: + +- No `.PropertyName` access +- Use `get column`, `select`, `$it.column`, or table operations instead +- Commands always receive predictable structured input, not strings or .NET types +::: + + +## Command Equivalents: + +| PowerShell | Nu | Task | +|-------------------------------------------------------------------|-----------------------------------------------|-------------------------------------------------------------------| +| `Get-ChildItem` | `ls` | List files in current directory | +| `Get-ChildItem ` | `ls ` | List files in given directory | +| `Get-ChildItem pattern*` | `ls pattern*` | Pattern-match files | +| `Get-ChildItem -Force -File -Hidden` | `ls --long --all` or `ls -la` | Detailed listing including hidden files | +| `Get-ChildItem \| Where-Object { $_.PSIsContainer }` | `ls \| where type == dir` | List directories only | +| `Get-ChildItem -Recurse -Filter *.rs` | `ls **/*.rs` | Recursive search for files | +| `Get-ChildItem -Recurse Makefile \| Select-Object -Expand Name` | `ls **/Makefile \| get name \| vim ...$in` | Pass matched paths to command | +| `Set-Location ` | `cd ` | Change directory | +| `Set-Location` | `cd` | Go to home directory | +| `Set-Location -` | `cd -` | Go to previous directory | +| `New-Item -ItemType Directory ` | `mkdir ` | Create a directory | +| `New-Item test.txt` | `touch test.txt` | Create a file | +| `command \| Out-File ` | `out> ` or `o> ` | Save output to file (raw) | +| `command \| Set-Content ` | `\| save ` | Save output to file (structured) | +| `command \| Out-File -Append ` | `out>> ` or `o>> ` | Append output to file | +| | `\| save --append ` | Append structured output | +| `command \| Out-Null` | `\| ignore` | Discard output | +| `cmd1 \| Tee-Object -FilePath log.txt \| cmd2` | `cmd1 \| tee { save log.txt } \| cmd2` | Tee output to file | +| `command \| Select-Object -First 5` | `command \| first 5` | Limit output to first N rows | +| `Get-Content ` | `open --raw ` | Display file contents | +| `Move-Item ` | `mv ` | Move file | +| `Get-ChildItem *.md \| ForEach-Object { $_.Name }` | `ls *.md \| each { $in.name }` | Iterate list values | +| `foreach ($i in 1..10) { $i }` | `for i in 1..10 { print $i }` | Loop over range | +| `Copy-Item ` | `cp ` | Copy file | +| `Copy-Item -Recurse ` | `cp -r ` | Copy directory recursively | +| `Remove-Item ` | `rm ` | Remove file | +| | `rm -t ` | Move file to trash | +| `Remove-Item -Recurse -Force ` | `rm -r ` | Remove directory recursively | +| `Get-Date ""` | `"" \| into datetime -f ` | Parse date | +| `"" -replace 'a','b'` | `str replace "a" "b"` | Replace substrings | +| `Select-String ` | `where $it =~ ` or `find ` | Search text | +| `Get-Help ` | `help ` | Get command help | +| `Get-Command` | `help commands` | List all commands | +| `Get-Command "**"` | `help --find ` | Search commands | +| `command1; if ($?) { command2 }` | `command1; command2` | Run second command only if first succeeds | +| `/tmp/$((Get-Random))` | `$"/tmp/(random int)"` | String interpolation | +| `$env:Path` | `$env.PATH` or `$env.Path` | Show PATH | +| `$LASTEXITCODE` | `$env.LAST_EXIT_CODE` | Exit code of last external command | +| `$env:PATH += ":/usr/bin"` | `$env.PATH = ($env.PATH \| append /usr/bin)` | Update PATH (temporary) | +| `Get-ChildItem Env:` | `$env` | List environment variables | +| `$env:FOO` | `$env.FOO` | Access environment variable | +| `Remove-Item Env:FOO` | `hide-env FOO` | Unset environment variable | +| `Set-Alias s "git status -sb"` | `alias s = git status -sb` | Temporary alias | +| `Get-Command FOO` | `which FOO` | Inspect command / alias / binary | +| `powershell -Command ""` | `nu -c ` | Run inline pipeline | +| `.\script.ps1` | `nu