Hacker News new | ask | show | jobs
by JamesSwift 2262 days ago
I dev on a Mac and do a lot of 'quality of life' scripting with Bash. I recently had to do something on a PC and figured I'd try out Powershell. I have to say, it was a joy. Dealing with objects instead of text is so refreshing, it really is a game changer especially when you start integrating with COM (e.g. excel).

The only things I found worse:

1 - error handling doesnt bubble in the same way. e.g. I can't do an equivalent of `set -e`, or do `cmd && other_cmd`

2 - return values are very nuanced. If you don't understand how function statement contribute to the result, you will spend a lot of time debugging odd issues

4 comments

As people mentioned there is `$ErrorActionPreference = "Stop"` but it's not equivalent to bash `set -e`. Looks like there is no consensus if we'll get something similar in the near future (https://github.com/PowerShell/PowerShell-RFC/pull/88)
The equivalent to `set -e` is setting the `ErrorActionPreference` variable to "Stop" - all errors become terminating.
$ErrorActionPreference = "Stop"

At the top of the script is the closest I fount to `set -e`

They added && recently, apparently.