Live data from Hacker News

“It's easier to port a shell than a shell script” (1998)

gopher.quux.org

51–60 of 68 posts

Re: “It's easier to port a shell than a shell script” (1998)

#51
post #19

Earlier quoted context omitted.

I know enough and have had enough tangential contact with PowerShell to know that it works on a fundamentally different paradigm, as it does not pipe text, but objects. As such, it's hard to say it's "better" since it's so different. I would hazard that it's better some respects for some things, and the reverse is true as well. It fits well into windows, but would not fit well into UNIX systems, where most things are…

That said, if they are easily comparable to bash, ksh, etc I specifically contrasted them against Bourne or C-like shells, so I thought that much was clear that they are not. I have tried PowerShell. I think this comment summarizes it well: https://lobste.rs/s/vzjalp/why_i_dislike_systemd/comments/sh...

That comment is utterly uninformed.

If you want to run a script simultaneously on a number of hosts, you use the Invoke-Command cmdlet (or it's alias icm).

If you want to stop a process, you use Stop-Process (or it's alias kill).

To copy files or directories you use the Copy-Item cmdlet (or one of it's aliases cp and copy).

Hence, to stop WINWORD on a host1, host2 and host3 and then copy a directory from host0 to each of them, you would write:

    icm host1,host2,host3 {kill -name WINWORD; cp \\host0\C$\source C:\dest }
As simple as it should be!

The commenter is correct that you cannot start an application in another session from remote. However, this is a security restriction that prevents cross-session contamination and shatter attacks. It is a (security) limitation of Windows, not of PowerShell.

Under Windows, all services run in session 0, the interactive user run in session 1, and if more users log on (e.g. remotely through PowerShell) they are each created in their own session. Windows put severe restrictions on what programs can do cross-session - even if the processes run under the same user account: They cannot send messages, interact with the desktop windows, inject code, start threads etc.

The commenter also alludes to other security settings that you'll encounter when you first start using PowerShell: - Execution of script files are disabled by default. You need to use the Set-ExecutionPolicy cmdlet to allow script execution, and for desktop editions you need to enable remote management. Both has secure-by-default values.

To enable script execution:

    Set-ExecutionPolicy RemoteSigned LocalMachine
I.e. scripts that originates from the Internet (downloaded through a browser or received through mail/IM/etc) or other untrusted zones require digital signatures to run; locally authored scripts are allowed to run with no digital signatures.

To enable remote management run this command:

    Enable-PSRemoting
On Windows Server versions it is now assumed that the administrator will want to use remote management, so it is enabled by default for servers. For desktops you'll need to set it through a group policy or with the command above.

Re: “It's easier to port a shell than a shell script” (1998)

#52

So the title of this link is from the title of the email. That in turn is a quote from Larry Wall, who do not seem to be present in the story at all.

Well, I assumed that the point of the quote is that it's fitting for the story, mentioning Larry was for attribution (which I see got removed from the title, I don't mind but I think it should've stayed in there for credit)

Yeah, i just came expecting to see something about the issues of porting scripts between shells or something. especially as there has been a whole lot of pro/con shell scripts as of late.

Re: “It's easier to port a shell than a shell script” (1998)

#53

Earlier quoted context omitted.

I don't think it is fundamentally different. When I think of a shell I think of pipes and interactivity. What you pass between through the pipe is secondary. The fundamental nature of the shell is those two things and everything else is just sugar on top. PowerShell has that and more so I'd say it is not fundamentally different and in fact it is objectively better.

The word "shell" in this context already means something. A text shell is a command line interpreter ( https://en.wikipedia.org/wiki/Shell_(computing)#Text_.28CLI.... ). There are many shells that do not use the pipeline convention (e.g., irb), so your attempt to redefine it to promote PowerShell fails from the start. PowerShell's object pipeline is functionally analogous to function chaining in languages like Ruby,…

> PowerShell's object pipeline is functionally analogous to function chaining in languages like Ruby, Python, and JavaScript

No, in those languages function results are bound upon returning from the function. PowerShell's pipeline would be more like function chaining where each function is a co-routine that can yield partial results, which would make it considerable more complicated.

So your attempt at trivializing PowerShell fails from the start.

For your information, here is roughly how a PowerShell pipeline is set up, processed and torn down:

1. BeginProcess is invoked for each command in the pipeline, starting with the last command of the pipeline, working towards the first. When each command is initialized this way, it can start receiving objects from preceding command on the pipeline. Each command may start produce objects already during this phase, as all subsequent commands are ready to process them. If it produces objects, ProcessRecord of the subsequent command is invoked immediately. 2. ProcessRecord is invoked on the first command of the pipeline. If it yields objects, ProcessRecord of the subsequent command is invoked for each object, thus "pushing" objects through 3. EndProcess is invoked for the first command of the pipeline. It it yields objects, ProcessRecord of the subsequent command is invoked for each object. When EndProcess completes for the first command of the pipeline, EndProcess is invoked for the subsequent command and so forth until EndProcess has been invoked for all commands of the pipeline.

As you can see, each cmdlet has 3 phases: initialization, processing and completion. All cmdlets (functions?) become active at the same time, with the control flow passing to each command (function?) multiple times during each phase. This can be implemented in any turing complete language, but function chaining is a lame attempt at trivializing it. Throw in reactive sequences and it may get closer.

Consider how Sort-Object (alias sort) is implemented: It does nothing during BeginProcess, during ProcessRecord it adds to an internal collection but does not yield any objects (yet), during EndProcess it sorts and yields all of the collected records. This is clearly analogous to how sort in byte/text stream is implemented: When the process starts it does nothing but initialize and starts listening on stdin, for each "line" on stdin it adds to an internal collection, and when stdin is closed it sorts the collection and writes the "lines" to stdout. 3 phases.

Even so, it doesn't really matter how it is implemented, a shell is inherently about how you interact with the shell.

> PowerShell's object pipeline does not exist outside of the .NET runtime and you can not stream objects between arbitrary executables outside of the .NET runtime.

You are locked in the Unix view of the world and is unable to consider that long standing assumptions about "the way to do it" may need a refresh. If you want to leverage objects for system management then yes, you need a system-wide object model. Unix was not built with an object model. Windows was sort-of build with an object model (handles) but it is not versatile enough as a system-wide management model.

However, the good thing about objects is that they are abstractions which can easily wrap existing operating system concepts, such as files, processes, access control lists, drivers, users, groups, network connections etc. .NET is a mature object model and with a lot of tooling. Building PowerShell so that the abstractions over network adapters, users etc become represented by .NET classes enable a lot of tooling and infrastructure right from the beginning.

Re: “It's easier to port a shell than a shell script” (1998)

#54

Earlier quoted context omitted.

I have never used PowerShell, so I don't know a lot about the details. But PowerShell pipes .NET objects from one command to the next, which are not just bytestreams but are objects, with methods and such. It's fundamentally different. In UNIX, you have bytes, and the underlying system doesn't know what they represent. Most tools assume they're ASCII or UTF-8 (or whatever) encoded text, but that's all they agree on.…

> It's fundamentally different. That's because the object pipeline is functionally analogous to function chaining within a single runtime like in Python or Ruby, not streaming data between arbitrary executables like in Unix pipelines. This would be a lot clearer if PowerShell advocates compared it to things that it's actually functionally analogous to, but they are trying to position it as a Unix shell competitor.

> That's because the object pipeline is functionally analogous to function chaining within a single runtime like in Python or Ruby

No it is not. See my response below.

Re: “It's easier to port a shell than a shell script” (1998)

#55
post #54

Earlier quoted context omitted.

> It's fundamentally different. That's because the object pipeline is functionally analogous to function chaining within a single runtime like in Python or Ruby, not streaming data between arbitrary executables like in Unix pipelines. This would be a lot clearer if PowerShell advocates compared it to things that it's actually functionally analogous to, but they are trying to position it as a Unix shell competitor.

> That's because the object pipeline is functionally analogous to function chaining within a single runtime like in Python or Ruby No it is not. See my response below.

Yes it is, and stop trying to pretend otherwise.

Your long-winded comments about PowerShell's internal language and runtime features are utterly irrelevant since they exist within with PowerShell runtime, just as the features of Ruby, Python, JavaScript, the JVM languages, etc all exist within those runtimes.

You also tried to falsely claim that cmdlets are not instances of .NET classes in a previous discussion (https://news.ycombinator.com/item?id=9461682) and your comments are perfect examples of how PowerShell advocates use long posts of handwaving, obfuscation, and verifiably false claims to try to pretend PowerShell's functionality is different than it actually is.

Re: “It's easier to port a shell than a shell script” (1998)

#56
post #19

Earlier quoted context omitted.

I know enough and have had enough tangential contact with PowerShell to know that it works on a fundamentally different paradigm, as it does not pipe text, but objects. As such, it's hard to say it's "better" since it's so different. I would hazard that it's better some respects for some things, and the reverse is true as well. It fits well into windows, but would not fit well into UNIX systems, where most things are…

That said, if they are easily comparable to bash, ksh, etc I specifically contrasted them against Bourne or C-like shells, so I thought that much was clear that they are not. I have tried PowerShell. I think this comment summarizes it well: https://lobste.rs/s/vzjalp/why_i_dislike_systemd/comments/sh...

The only attribute you contrasted was how they compare to powershell on the axis of better or worse, and I just stated my belief that it's hard to compare them accurately due to fundamental differences. That's not a strong basis for me to make assumptions about those shells.

By asking if inferno-shell and friends were easily comparable with C-like shells I was attempting to determine if they were additionally hard to compare with powershell, and infer from that your unfamiliarity with powershell. That, obviously, was a stretch.

Re: “It's easier to port a shell than a shell script” (1998)

#57
post #53

Earlier quoted context omitted.

The word "shell" in this context already means something. A text shell is a command line interpreter ( https://en.wikipedia.org/wiki/Shell_(computing)#Text_.28CLI.... ). There are many shells that do not use the pipeline convention (e.g., irb), so your attempt to redefine it to promote PowerShell fails from the start. PowerShell's object pipeline is functionally analogous to function chaining in languages like Ruby,…

> PowerShell's object pipeline is functionally analogous to function chaining in languages like Ruby, Python, and JavaScript No, in those languages function results are bound upon returning from the function. PowerShell's pipeline would be more like function chaining where each function is a co-routine that can yield partial results, which would make it considerable more complicated. So your attempt at trivializing P…

useerup, virtually everything in your comment is irrelevant handwaving and obfuscation, including a bunch of irrelevant comments about features that are internal to the PowerShell runtime.

No matter how much you want to try to talk around it, PowerShell is a .NET CLI, the object pipeline exists within its .NET runtime, and the commands are instances of .NET classes. Unix shells work primarily with arbitrary executables outside of the shell runtime using OS system calls to create pipelines with standard streams.

Here's the cold hard fact stated yet again: PowerShell's object pipeline is functionally analogous to function chaining in languages like Ruby, Python, and JavaScript, not Unix pipelines.

Re: “It's easier to port a shell than a shell script” (1998)

#58
post #54

Earlier quoted context omitted.

> That's because the object pipeline is functionally analogous to function chaining within a single runtime like in Python or Ruby No it is not. See my response below.

Yes it is, and stop trying to pretend otherwise. Your long-winded comments about PowerShell's internal language and runtime features are utterly irrelevant since they exist within with PowerShell runtime, just as the features of Ruby, Python, JavaScript, the JVM languages, etc all exist within those runtimes. You also tried to falsely claim that cmdlets are not instances of .NET classes in a previous discussion ( htt…

> You are the same person who tried to falsely claim that cmdlets are not instances of .NET classes

The fact stands, cmdlets can be implemented as .NET classes, but they can also be implemented through script (i.e. not .NET classes) or through manifests where cmdlets are generated for WMI/CIM classes.

I don't know why you continue to ignore this, or even why it is important. I point out that you are incorrect and point to a authoritative source that demonstrate the point.

The relevant section of the PowerShell section:

--- ... A module can contain one or more module members, which are commands (such as cmdlets and functions) and items (such as variables and aliases). The names of these members can be kept private to the module or they may be exported to the session into which the module is imported. There are three different module types: manifest, script, and binary. A manifest module is a file that contains information about a module, and controls certain aspects of that module's use. A script module is a PowerShell script file with a file extension of ".psm1" instead of ".ps1". A binary module contains class types that define cmdlets and providers. Unlike script modules, binary modules are written in compiled languages. Binary modules are not covered by this specification. Windows PowerShell: A binary module is a .NET assembly (i.e.; a DLL) that was compiled against the PowerShell libraries. ---

I will point out when your claims about PowerShell are incorrect. It's an opportunity to learn something. Please address the topic, not the poster.

Re: “It's easier to port a shell than a shell script” (1998)

#59
post #58

Earlier quoted context omitted.

Yes it is, and stop trying to pretend otherwise. Your long-winded comments about PowerShell's internal language and runtime features are utterly irrelevant since they exist within with PowerShell runtime, just as the features of Ruby, Python, JavaScript, the JVM languages, etc all exist within those runtimes. You also tried to falsely claim that cmdlets are not instances of .NET classes in a previous discussion ( htt…

> You are the same person who tried to falsely claim that cmdlets are not instances of .NET classes The fact stands, cmdlets can be implemented as .NET classes, but they can also be implemented through script (i.e. not .NET classes) or through manifests where cmdlets are generated for WMI/CIM classes. I don't know why you continue to ignore this, or even why it is important. I point out that you are incorrect and poi…

[deleted]

Re: “It's easier to port a shell than a shell script” (1998)

#60
post #58

Earlier quoted context omitted.

Yes it is, and stop trying to pretend otherwise. Your long-winded comments about PowerShell's internal language and runtime features are utterly irrelevant since they exist within with PowerShell runtime, just as the features of Ruby, Python, JavaScript, the JVM languages, etc all exist within those runtimes. You also tried to falsely claim that cmdlets are not instances of .NET classes in a previous discussion ( htt…

> You are the same person who tried to falsely claim that cmdlets are not instances of .NET classes The fact stands, cmdlets can be implemented as .NET classes, but they can also be implemented through script (i.e. not .NET classes) or through manifests where cmdlets are generated for WMI/CIM classes. I don't know why you continue to ignore this, or even why it is important. I point out that you are incorrect and poi…

Your statements about cmdlets are simply false, and you are again trying to handwave past the fact that PowerShell is a .NET CLI and that its object pipeline only exists within its .NET runtime and is analogous to function chaining within a single runtime like in Python or Ruby, not Unix pipelines.

From the Microsoft documentation, which I quoted to you in a previous discussion, so you should already know it (which would then indicate you are being deliberately dishonest): "Cmdlets are instances of .NET Framework classes; they are not stand-alone executables."

> they can also be implemented through script (i.e. not .NET classes)

Your statement here is factually wrong. They are called "advanced functions," previously "script cmdlets," mimic the behavior of true cmdlets ("bind as cmdlets"), but are not true cmdlets. They also exist within the .NET runtime, which is the relevant issue.

> through manifests where cmdlets are generated for WMI/CIM classes.

Then those generated cmdlets must be instances of .NET classes, because by definition that's what cmdlets are, and they exist within the .NET runtime, which is the relevant issue.

And in all cases, they exist within the PowerShell/.NET runtime and are not arbitrary executables written in arbitrary languages.

Thank you, however, for providing yet another demonstration of how PowerShell advocates consistently resort to handwaving, obfuscation, and false claims in order to try to pretend PowerShell is functionally different than it actually is.

Post reply on HN