Hacker News new | ask | show | jobs
by partdavid 641 days ago
For what it's worth, I've had the opposite experience, maybe because I work in a different domain. Personally, I still think using Powershell functions and treating lines as string objects is an improvement over bash and its mini-languages, anyway; and most standard Unix commands have Powershell close equivalents. Some Powershell expressions might be abstruse but so is, say, awk; but when you've learned awk you only know awk; whereas the Powershell technique you used (calculated fields in select-object, for example) is permanently useful. I do spend a lot of my time with various random APIs so Powershell is pretty joyful compared to (say) curl/jq or yq-ish stuff. There was a real adjustment period, of course, getting used to a new shell; but it was the best thing about my experiment with Windows (discovering a new shell that I now use on my Unix-like systems, because I did not end up wanting to adopt Windows).

So I'm curious what kinds of things you mean when you say you have to parse everything as text anyway. I suspect you've needed to a lot more of those kinds of tasks than I have.

1 comments

Powershell's CSV, XML and JSON handing is my favourite Powershell feature. Completely agree with you that it beats a *nix shell and things like jq. If I was interacting with those all day I might be convinced to use it more.

What I mean by parsing as text was more about actual commands.

I wasn't expecting 1:1, but as an example, let's say I wanted to get a list of local users on a machine.

On Windows I can use "Get-LocalUser". It returns an object with properties you can filter, output with a format, etc. Basic stuff that saves me doing any thinking. I like that. It's amazing how column titles add to the user friendliness.

On Linux, Get-LocalUser doesn't exist, so I could run something like "getent passwd". It's only option is to return a screen of text. There's no structure yet, just lines and colons. Now I can (even though I shouldn't) grab fields with cut, or awk, and filter with grep, and maybe output something pretty at the end with column. What does the 5th column mean again?

So on the Linux side, I've never been very motivated to use it, since I often have to fall back to old ways anyway.

Thanks, that makes a lot of sense. I can see a lot of similar cases especially for sysadmin things (systemctl, ifconfig, etc.).

One thing that was nice about my adopting Powershell as my daily shell is that for the most part, I could just use the same shell utilities as usual:

  getent passwd | cut -f6 -d':' | sort | uniq -c
Like, there's no problem running that in powershell. I know people have talked about "mixing" strings and objects but, I have to say that for me I've rarely run into a problem with it?

As you learn you can do a little more. Maybe you learn that group (group-object) can be used instead of the two commands at the end:

  getent passwd | cut -f6 -d':' | group
And for me, the nice thing is that when you learn something like that, it's leverageable across all your cases. You learned something about your tool, not just about the passwd file.

Is this better than bash? I don't think it's worse:

  getent passwd | %{ ($_ -split ':')[5] } | group
But then you might notice that your data is a CSV (C for colon in this case) and you might leverage some of the CSV-handling which works well in Powershell:

  getent passwd | convertfrom-csv -del ':' -h 'user','pwd','uid','gid','comment','home','shell' | group -prop 'shell'
Now you're cooking with structured data again. I think familiarity makes this kind of thing come naturally. And since these commands are pretty discoverable, because they're more consistent, and tab-completion and command-line editing are so much better than bash. It's easy to see how the above can be made terser by stashing it into utility function or a hashtable in your profile (e.g. so you could do "getent passwd | fields passwd" or something like that.

Now, I'm not going to tell someone it's worth the growing pains and adjustments to switch. It's like switching keyboard layouts. And matters of taste might turn you off, understandable. But for me there have been real benefits, and on its merits, I do think it makes a better shell. And it would be nice (from my perspective) if the community did some more work around these use cases and making them nicer for people.

You learn all of that, find yourself logged into somebody else’s server, and you only have bash again.

Sorry, trying to be funny, not dismissive.

I think shells in general could use some rethinking, considering they still feel pretty 80s.

Familiarity (or my lack of) is likely a big reason I’ll miss the obvious.

Zsh fills in many of the same checkboxes while being similar enough you don’t lose muscle memory when you find a bash shell somewhere.

Maybe someday something else will take over. Windows has the advantage there, for sure.

Oh, it's not dismissive at all. It's not just a real consideration, it's an overriding one. I switched my "daily driver" shell to powershell but I still write CI/CD scripts in bash, and docker entrypoints, and cloud-init userdata, and utilities, because it's niche enough to be too much to ask my coworkers and community folks to also switch.

I do wonder about the muscle memory thing. I think having to create scripts in bash keeps my hand in enough that I won't lose it too badly. At least I hope so. I compared switching shells to switching keyboard layouts; something I also did, and something where it's been some effort to retain enough muscle memory to not completely flail when presented with another computer.

Bash is bloated. I have seen bash executables in the megabytes range. Preinstalled bash is not an argument in favour of using it.
Extracted, this Linux build of Powershell (v7.4.5) 174MB.
Yeah, it's hard to do a direct comparison, because bash needs a bunch of other utilities to be useful and they also take up space. In theory you can pick and choose but woe be to you if you want to use bash without sed, awk, cut, etc.

But it's true that, like, you get help with Powershell but that might not matter on a system where you wouldn't choose to install man pages or something.