4 ms·
Yeah, keep in mind that the output is a fully-fledged object, it is not the text you see. The text is generated by the PowerShell host if the returned object m
by Fr0styMatt88 7y ago
Yeah, keep in mind that the output is a fully-fledged object, it is not the text you see. The text is generated by the PowerShell host if the returned object makes it back there and the host is set up to present that object to the user that way.
Take the following in PowerShell:
ls | sort DateTime -d
ls returns an array of objects, sort then sorts the array by each object’s DateTime field (and here I’m asking it to sort in descending order with -d). The point is that sort isn’t depending on any text output, so it works with any array of objects regardless of the command that returned them.
The other cool thing this enables is auto-complete awareness in the shell. If I typed:
ls | sort <Tab>
then the shell knows what makes sense in auto-completion here as ls has an actual return type and in this case it will give me a list of available fields that I can sort on.
For those unfamiliar: ls and sort here are shortened aliases to more wordy verb-noun commands. These (as well as a large bunch of others) are given to you by default.
- pjmlp 7y agoYeah, PowerShell is the only mainstream shell that behaves like the REPL environments from Xerox PARC workstations. Structured data with direct access to any OS API, regardless how it is provided, .NET, COM or straight C like DLL. UNIX world never had that, beyond trying to fit language repls as user shell, which on UNIX always feels like a leaky abstraction.