by publius_0xf3 · 3y ago · 0 comments
But jeez, the syntax. There's a lot to say, but the worst is that I'm never sure where I need to place parentheses. By making brackets in function calls optional, it just makes you end up writing Lisp-like code when the arguments are also function calls or arrays. You are forced to write parenthesized function calls anyways when invoking .NET commands, so they might as well make it universal instead of this chimerical compromise. It's a similar story with quotation marks around strings.
But it speaks to the strengths of the language that I still enjoy writing it anyways.
user@server$ grep('word', 'file.txt')
C:\ > notepad.exe()
And if they did make that the requirement it would be an instant dealbreaker for a lot of people coming from other shells. It is indeed a similar story with quotation marks around strings, in that you don't want to have to write: user@server$ grep 'word' 'file.txt'
when you could write user@server$ grep word file.txt
If the parser can tell from the context that the next token should be a string, it will read it as a string. If it can't tell, and the next token might be a command but you want it to be a string, then you have to quote it. If there's a space e.g. in the file path and you want it to be read as a single token, you have to quote it. Always quoting won't break anything, it's just unnecessary. 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') 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!Hasn't been a thing for a while now.
The other thing I find is by thinking out the process of what I need and communicating to the LLM is I tend to make better scripts that have more functionality since I'm thinking about what I want done, and not thinking about just getting the syntax correct.
So much tedium is now easy if I can remember 'powershell can do it, and GPT can write it for me'.
It makes the syntax quite a lot cleaner, albeit sometimes less convenient, but more coherent.
With Powershell Core being the same on Windows, Linux and Mac OS, I find it much better to write small scripts with it, and more portable too. Never have to find out that the options to sed or another utility isn’t the same on macOS vs Linux for example.
Meh. Powershell, like most things windows, is just a dumbed down version of its unix equivalent to cater to its 'lower-skilled' user base. The best thing about powershell is its documentation and help section. It's far more 'detailed' and far more examples than its unix counterpart. How many times do you just wish a man page just had an example that you tinker with to get what you want? With powershell, you get that. Another thing going for powershell on windows ecosystem is that microsoft is tying powershell with their servers to make administration simpler and easier.
But powershell certainly isn't python or perl.
Two sentences ago you said helping people was dumbing down for low skill users. Hmm.
> "Another thing going for powershell on windows ecosystem is that microsoft is tying powershell with their servers to make administration simpler and easier."
They have been untying PowerShell from their servers for 7 years. PowerShell current version doesn't ship with Windows and does run on macOS and Linux.
> But powershell certainly isn't python
PowerShell has a good interactive shell, better/more convenient introspection/reflection, integrates more thoroughly with its underlying language (C#), has more humane defaults (case insensitivity).