News for hackers. Stuff that matters.
Re:“It's easier to port a shell than a shell script” (1998) by dkarapetyan on Sunday August 23, 2015 @02:17AM (#10104830)
You should try powershell. It's actually pretty good and is much better than unix shells.
Re:“It's easier to port a shell than a shell script” (1998) by pjc50 on Sunday August 23, 2015 @05:16AM (#10105091)
It's almost better. It's good for automating some system administration tasks. It's not so good for text processing; there are a number of traps and mis-steps. The object pipelines are great, but have to be held in memory (you can't pipe an intermediate state to disk). By default text output wraps at the terminal width even if you're writing to a file, which is just stupid and inconvenient for further automatic processing.

In order to write a script, you first have to change your system security settings.

More subtly, because it's comparatively new it's not very dogfooded and there isn't a rich source of examples. UNIX systems usually have lots of shell scripts in /etc for you to learn from.

Re:“It's easier to port a shell than a shell script” (1998) by kbenson on Sunday August 23, 2015 @02:51AM (#10104873)
It has it's pros and cons, but in the end it's fundamentally different. Powershell wouldn't work nearly as well on a UNIX system, where much of the tooling is already just text, provided by many different sources, and uses a much more diverse set of utilities. Text makes a good lowest common denominator in that situation.
Re:“It's easier to port a shell than a shell script” (1998) by tatterdemalion on Sunday August 23, 2015 @03:18AM (#10104914)
"Text" only makes a good lowest common denominator on UNIX because the designers of UNIX decided that ASCII would be the lowest common denominator of the system. The designers of modern Windows decided that MSIL objects would be their lowest common denominator.

If the UNIX designers had chosen some other lowest common denominator, all of these diverse utilities would be communicating over that protocol instead of ASCII. The choice to use "text" came first and the ecosystem came afterward.

Re:“It's easier to port a shell than a shell script” (1998) by AnthonyMouse on Sunday August 23, 2015 @11:17AM (#10105686)
> "Text" only makes a good lowest common denominator on UNIX because the designers of UNIX decided that ASCII would be the lowest common denominator of the system. The designers of modern Windows decided that MSIL objects would be their lowest common denominator.

"Text" makes a good lowest common denominator because it's low. Everything, including humans looking at it, can deal with text. Essentially all programming languages on all platforms provide basic primitives analogous to getline(), find_first_of(), substr(), etc. You can take text from Unix and easily do something useful with it on any arbitrary platform.

MSIL assumes an entire infrastructure that isn't universally available. You can't take MSIL from Windows and easily do something useful with it on any arbitrary platform. It requires you to have a solid .NET virtual machine for your operating system, an API for dealing with MSIL, bindings for that API in every language you want to use, etc.

Re:“It's easier to port a shell than a shell script” (1998) by tatterdemalion on Sunday August 23, 2015 @06:13PM (#10106926)
Users of System360 computers, which used EBCDIC instead of ASCII, might not agree with you about the inherent portability of ASCII-based text interchange. Not saying .NET objects are as portable, but it's a continuum and a trade off.
Re:“It's easier to port a shell than a shell script” (1998) by AnthonyMouse on Sunday August 23, 2015 @09:32PM (#10107462)
ASCII and EBCDIC are just different ways of encoding the same information. It's like saying comma-delimited files aren't portable because there are also tab-delimited files and some programs support one or the other. It doesn't matter because there are trivial, widely available utilities to convert between them.

There is nothing analogous to convert MSIL to. EBCDIC and ASCII both have a representation for 'A'. Only .NET has "Microsoft.Win32.Registry.CurrentUser.CreateSubKey()".

Re:“It's easier to port a shell than a shell script” (1998) by MrQuincle on Sunday August 23, 2015 @04:39AM (#10105037)
Can you explain me a bit the difference if you mind (I don't know much about Windows).

In Linux/Unix I can also pipe audio to /dev/audio for example. And image processing through a sequence of steps by pipes is quite often done. Are these objects coming with default metaparameters to make piping easier? Or are there other things implemented that might be cool?

Re:“It's easier to port a shell than a shell script” (1998) by tatterdemalion on Sunday August 23, 2015 @05:05AM (#10105072)
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. In practice, you're working almost always working with structured data - tables or lists or mappings - but you have to remember that for the output of this program, you want to cut on '=' and take -f4, and first you need to pipe it through head and tail to clean up some junk output[1], and this other thing for that program, and whatever.

[1] This is a way to get the `time` field from the output of `ping`.

Re:“It's easier to port a shell than a shell script” (1998) by integraton on Sunday August 23, 2015 @12:19PM (#10105864)
> 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.

Re:“It's easier to port a shell than a shell script” (1998) by useerup on Sunday August 23, 2015 @02:16PM (#10106270)
> 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.

[dead]
Re:“It's easier to port a shell than a shell script” (1998) by useerup on Sunday August 23, 2015 @03:24PM (#10106461)
> 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.

[dead]
Re:“It's easier to port a shell than a shell script” (1998) by dang on Monday August 24, 2015 @12:53AM (#10107972)
Your comments have been crossing over personal attacks. That's not allowed on HN. Please post civilly or not at all.
Re:“It's easier to port a shell than a shell script” (1998) by useerup on Sunday August 23, 2015 @05:36PM (#10106826)
> Then those generated cmdlets must be instances of .NET classes, because by definition that's what cmdlets are

Nope. The problem is that you searched for confirmation that cmdlets was "just" .NET classes (I really don't get why that is important), and then you dive into documentation for C# programmers and point out how the documentation for C# programmers is telling the C# programmer that if he wants to create a cmdlet he can do it with a C# class. D-oh!

When I point to the PowerShell specification and demonstrates how it does not claim that cmdlets are .NET classes you ignore it.

I point out how it enumerates the 3 different ways to make cmdlet modules: Binary, script and manifest, of which only the binary module variety implement cmdlets as classes.

You could equally well claim that Web Services are just MVC Controllers, because in the documentation for MVC I can find out how to implement web services using MVC controllers.

> ... and they exist within the .NET runtime, which is the relevant issue

Why? If the .NET runtime has become sediment to the point where the OS is always distributed with the runtime, where important OS functions (like troubleshooting) is implemented using the runtime, where remote administration is based on the runtime, at what point do you accept the runtime as part of the OS?

.NET IS part of Windows now, has been since Windows 7 SP1 (IIRC). Troubleshooting packs, guides etc. are written using PowerShell. When your network gets the hiccups, and Windows proactively offers to troubleshoot the network connection, it is PowerShell that is running underneath. The new PackageManager is PowerShell based.

> 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.

No need for snide remarks. I stand by all of my claims. It is you who selectively quote C# programmers documentation out of context. All you have proven is that if a C# programmer wants to create a cmdlet using C#, he must implement it using a class.

Re:“It's easier to port a shell than a shell script” (1998) by integraton on Sunday August 23, 2015 @11:56AM (#10105799)
PowerShell's object pipeline only exists within the PowerShell/.NET runtime and is functionally analogous to method/function chaining in languages like JavaScript and Ruby. The object pipeline does not exist outside of the PowerShell/.NET runtime.

Pipelines in Unix shells use OS-level functionality to connect standard streams of data, often encoded as text, between arbitrary executables written in any language.

The reason this is confusing is because one of the main tactics used in PowerShell promotion is to disingenuously compare PowerShell's "object pipeline" to Unix pipelines in order to try to make it appear to be more novel than it is, when they should be comparing it to what it's functionally equivalent to, which is function chaining within a single runtime.

Re:“It's easier to port a shell than a shell script” (1998) by useerup on Sunday August 23, 2015 @04:55PM (#10106709)
> which is function chaining within a single runtime

If PowerShells pipelines are merely equivalent to function chaining, then you should have no problem replicating the following very simple pipeline with function chaining in Ruby, Python or JavaScript:

    cat log.txt -wait | sls "error"
In case you need an explanation for what it is doing: It continously monitors the log.txt file for new lines, and selects those that contains the substring "error".

But I am curious: Why is it important whether the pipelines could be implemented using function chaining or not? PowerShell is a shell where I interact with the system through commands. Yes - those commands are not the typical Unix executables - but they act as commands within the shell

Is your problem that it is not a Unix shell? You could equally well say that Unix shell pipelines are just processes connected by file descriptors. That is factually correct but does not represent the true utility of pipelines.

PowerShell pipelines are not file descriptors. PowerShell commands do not execute in separate processes. But PowerShell commands are versatile and can be combined in a way analogous to Unix shell pipelines where the output of one command is consumed and acted upon by the next command.

The object of a operating system command line shell is to expose the operating system features to the user of the shell. Why does it matter whether it uses Unix file descriptors. Even if PowerShell pipelines were equivalent to "just" chained functions, why does it matter?

I get the point that you need the .NET runtime to run PowerShell, because it is implemented using .NET. At what point do we consider a runtime part of the operating system. When it is intrinsically distributed with the operating system and cannot be uninstalled?

Re:“It's easier to port a shell than a shell script” (1998) by kbenson on Monday August 24, 2015 @03:19AM (#10108353)
To underscore how the idea of a UNIX shell working on file descriptors between executables isn't really important, it's worth nothing that bash allows piping between it's built in commands/keywords. Not only can you pipe the aggregates output from a for, if or while construct, you can pipe the output of bash builtins such as bg, fg and disown.
Re:“It's easier to port a shell than a shell script” (1998) by kazinator on Sunday August 23, 2015 @10:30AM (#10105580)
"objects" means data structures. It means you can have some structure with fields, or list or array or whatever as the output of one command, and input of the next one, so the next one doesn't have to do character-level parsing.

Of course, this kind of piping is present in nice languages that precede the PowerShell.

A one page Lisp macro will give you a left-to-right syntactic sugar for filtering. Clojure has a threading operator, Ruby has cascades of dots: object.{ blah }.foo().bar() ... and so on.

Re:“It's easier to port a shell than a shell script” (1998) by tatterdemalion on Sunday August 23, 2015 @06:15PM (#10106934)
This is not what "objects" means (objects have methods), and .NET objects are a much higher level abstraction than structured data.
Re:“It's easier to port a shell than a shell script” (1998) by pdkl95 on Sunday August 23, 2015 @03:26AM (#10104927)
man locale(1)

Non-ASCII has been supported for a long time.

Re:“It's easier to port a shell than a shell script” (1998) by tatterdemalion on Sunday August 23, 2015 @03:52AM (#10104974)
This is obviously not what I was talking about. I was talking about data representations heterogenous to the idea of "text".

I used "ASCII" instead of "text" to stress that "text" is just a protocol like anything else. The UNIX I'm running is set to use UTF8.

Re:“It's easier to port a shell than a shell script” (1998) by dkarapetyan on Sunday August 23, 2015 @03:21AM (#10104920)
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.
Re:“It's easier to port a shell than a shell script” (1998) by integraton on Sunday August 23, 2015 @12:12PM (#10105842)
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, Python, and JavaScript, not Unix pipelines. 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 can't compare an apple to an orange and say one is "objectively better," no matter how hard PowerShell advertisers try to pretend their apple is an orange.

Re:“It's easier to port a shell than a shell script” (1998) by useerup on Sunday August 23, 2015 @01:25PM (#10106094)
> 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) by integraton on Sunday August 23, 2015 @02:49PM (#10106377)
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) by useerup on Sunday August 23, 2015 @05:40PM (#10106836)
> 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.

Ok, what then is the functionally analogous function chaining of Ruby, Python or JavaScript to the following:

    cat log.txt -wait | sls "error"
A simple function chain will do.
Re:“It's easier to port a shell than a shell script” (1998) by viraptor on Sunday August 23, 2015 @02:26AM (#10104843)
Better than Unix tools may be debatable. (Syntax for basic file operations is a bit verbose) But it's definitely better integrated into overall system administration than any shell available on Unix.
Re:“It's easier to port a shell than a shell script” (1998) by KnightHawk3 on Sunday August 23, 2015 @02:25AM (#10104839)
It's petty but I can't get over the case sensitive command names with capital letters in it.

They are honestly too long.

Re:“It's easier to port a shell than a shell script” (1998) by oblio on Sunday August 23, 2015 @04:04AM (#10104996)
It has aliases for 90% of those commands, though.
Re:“It's easier to port a shell than a shell script” (1998) by AndrewGaspar on Sunday August 23, 2015 @04:16AM (#10105006)
PowerShell is not case sensitive.
Re:“It's easier to port a shell than a shell script” (1998) by vezzy-fnord on Sunday August 23, 2015 @02:26AM (#10104841)
It might be better than Bourne or C-derived shells, but I have a hard time conceding it beats for instance Inferno shell, es or rc.
Re:“It's easier to port a shell than a shell script” (1998) by kbenson on Sunday August 23, 2015 @02:48AM (#10104866)
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 already just text.

I haven't used inforno-shell, es or rc, so can't comment on them directly. That said, if they are easily comparable to bash, ksh, etc, then you probably owe it to yourself to see what powershell is about and why it's fundamentally different.

Re:“It's easier to port a shell than a shell script” (1998) by vezzy-fnord on Sunday August 23, 2015 @02:57AM (#10104879)
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...

Re:“It's easier to port a shell than a shell script” (1998) by useerup on Sunday August 23, 2015 @12:26PM (#10105889)
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) by kbenson on Sunday August 23, 2015 @02:47PM (#10106371)
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) by moron4hire on Sunday August 23, 2015 @09:30AM (#10105438)
That's because shells on Windows aren't management tools. That role is filled by Group Policy.
Re:“It's easier to port a shell than a shell script” (1998) by x1024 on Sunday August 23, 2015 @06:52AM (#10105219)
Haha, yes. Microsoft has always delivered things that are "better" than the standards they are written against.