|
| 1 | +# Coming from PowerShell |
| 2 | + |
| 3 | +::: tip |
| 4 | +PowerShell pipelines pass rich **.NET objects**, which allow property access like `$process.Name` or piping objects directly into cmdlets that understand them. |
| 5 | + |
| 6 | +Nushell pipelines, by contrast, pass **structured data** such as tables, lists, and values. |
| 7 | +This means: |
| 8 | + |
| 9 | +- No `.PropertyName` access |
| 10 | +- Use `get column`, `select`, `$it.column`, or table operations instead |
| 11 | +- Commands always receive predictable structured input, not strings or .NET types |
| 12 | +::: |
| 13 | + |
| 14 | + |
| 15 | +## Command Equivalents: |
| 16 | + |
| 17 | +| PowerShell | Nu | Task | |
| 18 | +|-------------------------------------------------------------------|-----------------------------------------------|-------------------------------------------------------------------| |
| 19 | +| `Get-ChildItem` | `ls` | List files in current directory | |
| 20 | +| `Get-ChildItem <dir>` | `ls <dir>` | List files in given directory | |
| 21 | +| `Get-ChildItem pattern*` | `ls pattern*` | Pattern-match files | |
| 22 | +| `Get-ChildItem -Force -File -Hidden` | `ls --long --all` or `ls -la` | Detailed listing including hidden files | |
| 23 | +| `Get-ChildItem \| Where-Object { $_.PSIsContainer }` | `ls \| where type == dir` | List directories only | |
| 24 | +| `Get-ChildItem -Recurse -Filter *.rs` | `ls **/*.rs` | Recursive search for files | |
| 25 | +| `Get-ChildItem -Recurse Makefile \| Select-Object -Expand Name` | `ls **/Makefile \| get name \| vim ...$in` | Pass matched paths to command | |
| 26 | +| `Set-Location <dir>` | `cd <dir>` | Change directory | |
| 27 | +| `Set-Location` | `cd` | Go to home directory | |
| 28 | +| `Set-Location -` | `cd -` | Go to previous directory | |
| 29 | +| `New-Item -ItemType Directory <path>` | `mkdir <path>` | Create a directory | |
| 30 | +| `New-Item test.txt` | `touch test.txt` | Create a file | |
| 31 | +| `command \| Out-File <path>` | `out> <path>` or `o> <path>` | Save output to file (raw) | |
| 32 | +| `command \| Set-Content <path>` | `\| save <path>` | Save output to file (structured) | |
| 33 | +| `command \| Out-File -Append <path>` | `out>> <path>` or `o>> <path>` | Append output to file | |
| 34 | +| | `\| save --append <path>` | Append structured output | |
| 35 | +| `command \| Out-Null` | `\| ignore` | Discard output | |
| 36 | +| `cmd1 \| Tee-Object -FilePath log.txt \| cmd2` | `cmd1 \| tee { save log.txt } \| cmd2` | Tee output to file | |
| 37 | +| `command \| Select-Object -First 5` | `command \| first 5` | Limit output to first N rows | |
| 38 | +| `Get-Content <path>` | `open --raw <path>` | Display file contents | |
| 39 | +| `Move-Item <source> <dest>` | `mv <source> <dest>` | Move file | |
| 40 | +| `Get-ChildItem *.md \| ForEach-Object { $_.Name }` | `ls *.md \| each { $in.name }` | Iterate list values | |
| 41 | +| `foreach ($i in 1..10) { $i }` | `for i in 1..10 { print $i }` | Loop over range | |
| 42 | +| `Copy-Item <source> <dest>` | `cp <source> <dest>` | Copy file | |
| 43 | +| `Copy-Item -Recurse <source> <dest>` | `cp -r <source> <dest>` | Copy directory recursively | |
| 44 | +| `Remove-Item <path>` | `rm <path>` | Remove file | |
| 45 | +| | `rm -t <path>` | Move file to trash | |
| 46 | +| `Remove-Item -Recurse -Force <path>` | `rm -r <path>` | Remove directory recursively | |
| 47 | +| `Get-Date "<date>"` | `"<date>" \| into datetime -f <format>` | Parse date | |
| 48 | +| `"<str>" -replace 'a','b'` | `str replace "a" "b"` | Replace substrings | |
| 49 | +| `Select-String <pattern>` | `where $it =~ <pattern>` or `find <pattern>` | Search text | |
| 50 | +| `Get-Help <command>` | `help <command>` | Get command help | |
| 51 | +| `Get-Command` | `help commands` | List all commands | |
| 52 | +| `Get-Command "*<string>*"` | `help --find <string>` | Search commands | |
| 53 | +| `command1; if ($?) { command2 }` | `command1; command2` | Run second command only if first succeeds | |
| 54 | +| `/tmp/$((Get-Random))` | `$"/tmp/(random int)"` | String interpolation | |
| 55 | +| `$env:Path` | `$env.PATH` or `$env.Path` | Show PATH | |
| 56 | +| `$LASTEXITCODE` | `$env.LAST_EXIT_CODE` | Exit code of last external command | |
| 57 | +| `$env:PATH += ":/usr/bin"` | `$env.PATH = ($env.PATH \| append /usr/bin)` | Update PATH (temporary) | |
| 58 | +| `Get-ChildItem Env:` | `$env` | List environment variables | |
| 59 | +| `$env:FOO` | `$env.FOO` | Access environment variable | |
| 60 | +| `Remove-Item Env:FOO` | `hide-env FOO` | Unset environment variable | |
| 61 | +| `Set-Alias s "git status -sb"` | `alias s = git status -sb` | Temporary alias | |
| 62 | +| `Get-Command FOO` | `which FOO` | Inspect command / alias / binary | |
| 63 | +| `powershell -Command "<commands>"` | `nu -c <commands>` | Run inline pipeline | |
| 64 | +| `.\script.ps1` | `nu <script file>` | Run script file | |
| 65 | +| `Get-Location` or `$PWD` | `pwd` or `$env.PWD` | Show current directory | |
| 66 | +| `Read-Host` | `let var = input` | Read user input | |
| 67 | +| `Read-Host -AsSecureString` | `let secret = input -s` | Read secret input | |
0 commit comments