4 ms·
Powershell is not "just a copy of how unix works". Powershell lets you work with objects instead of wrangling text. You call real functions with real objects as
by legalcorrection 5y ago
Powershell is not "just a copy of how unix works". Powershell lets you work with objects instead of wrangling text. You call real functions with real objects as real parameters and get real objects returned back to you. You can pipe those objects, iterate over them, etc. You can call into .NET and even Win32. In bash, all you have is 1) executing binaries and 2) hacks emulating real variables and functions and control flow but that are really just parsing and passing strings around.
- hajile 5y agoBash gives you access to FILES. Those files can be text or they could be binary data representing objects of ANY kind. Your definitional separation between functions and binaries is at best incredibly thin. Bash itself is turing complete. Other shells offer other (better) languages as well. Linux uses D-Bus which has similarities to COM, but nobody has seen the point of replacing normal POSIX with it. Nothing is stopping you though.
- legalcorrection 5y agoMy point is that in bash, all you have is the bash language, which is just layers of hacks to cover up the fact that you're just slinging strings around, and the ability to start other processes with command line arguments (again, strings). In powershell, you can certainly run programs with arguments, but you're mostly going to be calling functions that take actual objects as parameters, not just escaped strings that you hope are in the right format. Most OS functionality you can imagine is exposed as powershell commands, and most of the rest can be called as .NET methods (which are just as easy to call). And with a little more work you can call win32 functions. Between all of that, that's the entire OS API surface. You have variables with data types, both basic types like int/string/etc. but also objects with fields and methods like arrays, hash tables, and such. And the functions are designed to receive such objects as inputs and as outputs. Again, in bash, you accomplish the same thing with stuff like xargs and array expansions, all just fancy string manipulation. Yes, bash is obviously Turing complete. Yes, you can accomplish anything in bash. But it's not pretty. And since everything is just glorified string manipulation, it's hard to write rigorous and robust bash programs that don't blow up in the face of weird directory or file names or other edge cases.
- hajile 5y ago> which is just layers of hacks to cover up the fact that you're just slinging strings around This is NOT true. You are slinging around FILES. They might be text and they might not be text. Nothing keeps bash from opening up a file of raw C structs and parsing out the objects to use them. The reason this isn't done very much is because it is seldom useful. 99% of files that users want to process on the command line are human-readable text files (this is just as true on Windows as on POSIX). The rest of what is done consists mostly of piping the non-text through programs dedicated to handling complex data. The most common use case for "objects" is parsing JSON and tools like jq exist to do this. There are also separate tools for most of the common non-text formats. > Yes, you can accomplish anything in bash. But it's not pretty. Powershell one-liners aren't pretty either. If you're writing complex programs on the command line, you are making a big mistake. A bug in your code could be catastrophic. Such programs need to be tested first anyway. Shebang files have been around for decades to solve this issue. Just write your code in a "real" language like python or perl.
- legalcorrection 5y ago>Nothing keeps bash from opening up a file of raw C structs and parsing out the objects to use them ... so you're parsing strings. In bash, all values are strings (with a half-exception for the the phantasms of integers and lists).