4 ms·
I've often gotten caught out using commas to separate arguments like most other scripting languages ever. One of those things you need to remember when writing
by benbristow 3y ago
I've often gotten caught out using commas to separate arguments like most other scripting languages ever. One of those things you need to remember when writing Powershell scripts!
- jodrellblank 3y agoCan you give an example of where/how? I imagine you don't get caught out writing Bash scripts like: grep -e,-i,'\bneedle\b',file.txt | cut -F,2,-d,':' Because that's so contextually distinct from Python/JavaScript/Ruby; in shells (and APL, J, LISPs), arrays of commands and their arguments are space separated rather than comma separated. Similar in PowerShell, where it looks like shell it tends to work like shell: get-childitem -Path c:\ -Filter *.txt -Force Where it looks like scripting language it tends to work like one: $host.ui.WriteLine('Green', 'Yellow', 'Hi')
- benbristow 3y agoWith functions function Get-Something { Param ( [Parameter(Mandatory=$true, Position=0)] [string] $Name, [Parameter(Mandatory=$true, Position=1)] [int] $Id ) # Write the output to the console Write-Output "Name: $Name, Id: $Id" } Get-Something "Alice" 42 If you were to call Get-Something("Alice", 42) It would pass "Alice", 42 to the first parameter. You can use named parameters to get round this, e.g. Get-Something -Name "Alice" -Id 42 Still a bit of a gotcha!