Live data from Hacker News

Two Months with Powershell on a Unix

code.joejag.com

61–70 of 113 posts

Re: Two Months with Powershell on a Unix

#61

>For example, if we wanted to get the first three files from ls I’d do something like `ls | head -n 3`. In Powershell, it’s `$(dir)[0..2]` since the dir command is returning an array which I can index into. You could do that, but the way to write it in the bash way would be `dir | select -first 3` >a quick Google told me to use `echo | openssl s_client -showcerts -servername joejag.com -connect joejag.com:443 2>/dev/…

> You could do that, but the way to write it in the bash way would be `dir | select -first 3` I would have said "ls | head -n3" as well. I've never heard of "select". I just tried your suggestion and it doesn't appear to work: $ dir | select -first 3 bash: syntax error near unexpected token `3'

It's because it's a PowerShell syntax. What the parent meant was "here's how to write it in PowerShell so that it still has a 'unix' feel to it (ie: composing commands with pipes and option switches)".

Re: Two Months with Powershell on a Unix

#62

>For example, if we wanted to get the first three files from ls I’d do something like `ls | head -n 3`. In Powershell, it’s `$(dir)[0..2]` since the dir command is returning an array which I can index into. You could do that, but the way to write it in the bash way would be `dir | select -first 3` >a quick Google told me to use `echo | openssl s_client -showcerts -servername joejag.com -connect joejag.com:443 2>/dev/…

>You could do that, but the way to write it in the bash way would be `dir | select -first 3` Fyi, `dir | select -first 3` also works in PowerShell.

Yes, this is what the parent meant: it is valid PowerShell. It wouldn't work by default in Bash unless you had `dir` and `select` defined there somehow.

Re: Two Months with Powershell on a Unix

#63

I like that it passes objects instead of strings, I could see that being really useful. Get-Member will list all methods and properties of an object.

Another shell that has a similar philosophy is Nu[1]. I think the idea of structured shells (and typed shells?) is a very interesting path to improve UX and prevent certain kinds of common error.

[1]: https://github.com/nushell/nushell

Re: Two Months with Powershell on a Unix

#64

I am dead serious. Powershell should replace (bash) shell scripting under any Linux. I find shell scripts terrible, I've learned to switch to Python quickly, despite the overhead. Powershell is very command-line friendly, with easy tab-completion of commands. I've worked with it extensively on Windows, creating large worklflows with it, it's very nice. Powershell even has a unit test tool called 'pester' which is fun…

Powershell is kind of half baked. In Powershell you mostly interact with in a functional manner (chaining, filtering, etc) but Powershell for whatever reason provides nearly zero functional programming features which makes it painful to script in. IMO anyways

Re: Two Months with Powershell on a Unix

#65
here is my opinion on `When X is going to replace bash?`

The story goes on like this:

You went to DataCentre, logged in to an internal machine, something happened (eg failure, diagnostic necessary et.al.) which you need to fix.

given condition, you don't have internet connection inside (air-gapped)

- You most likely have man-pages installed and having examples what to do in them,

- `--help` yields some sensible output

- Shell is 'fast', errors are well-known and defined.

Also, take into account of other comments that are discussing `how to do x` and why it doesn't/wouldn't work on PowerShell

Re: Two Months with Powershell on a Unix

#66
post #62

Earlier quoted context omitted.

>You could do that, but the way to write it in the bash way would be `dir | select -first 3` Fyi, `dir | select -first 3` also works in PowerShell.

Yes, this is what the parent meant: it is valid PowerShell. It wouldn't work by default in Bash unless you had `dir` and `select` defined there somehow.

"dir" is commonly available on Linux and "select" is a bash built-in, which is probably why so many of us were confused by the comment :)

Re: Two Months with Powershell on a Unix

#68
post #7

If you don't want PowerShell reporting your activities back to the mothership, don't forget to set POWERSHELL_TELEMETRY_OPTOUT=1 in your environment before launching PowerShell!

A shell with telemetry. Insane.

Shellemetry, if you will.

Re: Two Months with Powershell on a Unix

#69
post #54

I spent some time with Powershell on Windows recently, more time than I am used to. Powershell is a clear winner over CMD.EXE by a mile, but… - As an interactive shell, it suffers from an ecosystem which is much poorer than the bash/zsh ecosystem, - As a scripting language, I’m going to use Python or Go the moment anything becomes larger than a few lines, - Installing Posh Git is just a really mediocre experience (in…

My biggest issue with powershell is how undiscoverable it is. Good luck doing anything without searching for commands in a web browser. But maybe that's just a result if it being so new. 'ls' has been around for almost 50 years... What it really feels like is a complete programming language inside of notepad.exe because of the historically terrible windows command prompt.

Yes, but, POSIX shells aren’t that much more discoverable, either.

It takes loads of reading and trial and error to become competent in any command line.

Re: Two Months with Powershell on a Unix

#70

I am dead serious. Powershell should replace (bash) shell scripting under any Linux. I find shell scripts terrible, I've learned to switch to Python quickly, despite the overhead. Powershell is very command-line friendly, with easy tab-completion of commands. I've worked with it extensively on Windows, creating large worklflows with it, it's very nice. Powershell even has a unit test tool called 'pester' which is fun…

No one should script for bash or PowerShell for that matter.

If you have to write shell scripts on Linux then target #!/bin/sh and write it so that it works in other shells.

The problem with Powershell for scripting is that it is just good enough that people don't go use something better like Python or Ruby.

Post reply on HN