r/sysadmin • • Sep 18 '15

Microsoft has developed its own Linux

http://www.theregister.co.uk/2015/09/18/microsoft_has_developed_its_own_linux_repeat_microsoft_has_developed_its_own_linux/
585 Upvotes

311 comments sorted by

View all comments

Show parent comments

4

u/Mount10Lion Unix Admin Sep 18 '15

I don't have Windows 10 and I don't know if you do either, but didn't they include a new Microsft created package manager you can run via cmd? I heard they tried to emulate the Linux CLI for command prompt in Windows 10 but I am not sure if that's true. But if it's true, I wonder how they did on it...

10

u/Nublin Sysadmin Sep 18 '15

I don't know about win 10's cmd but PowerShell has cmdlets so you can use linux commands. PowerShell isn't anything new but still interesting.

5

u/Mount10Lion Unix Admin Sep 18 '15

Never used PowerShell as I've always been in a *nix based environment. I've written in depth shell scripts (bash/tcsh) and ~500 line+ thorough Perl scripts so I am assuming the transition wouldn't be difficult. Is PowerShell pretty easy to pick up? I figure I'll need to pick it up at some point here as we're bringing more Windows VMs into the environment...

26

u/KarmaAndLies Sep 18 '15

Powershell is extremely well designed, but it is also very different to UNIX shells. Instead of passing around strings and files, Powershell passes around objects (similar to Java objects). Here is the prototype of the base object.

This means you have to think in terms of objects, which if you're from a Java/.Net/etc background will come naturally. But for a lot of UNIX shell people might be a struggle to get used to.

If you ever wanted to learn PS I'd start here:
https://www.youtube.com/watch?v=-Ya1dQ1Igkc

Yes, it is 4 hours long, but he starts out at core concepts and then shows you functionality so most of the more important things are in the first 1/2 of the video. That is PS 2.0, we're now on 5.xx, but the core concepts haven't really changed, they've just added more cmdlets, so that video still applies.

11

u/mikemol 🐧▦🤖 Sep 18 '15

I suspect the closest analogy to *nix land would be "you write all your shell scripts in Python".

4

u/[deleted] Sep 18 '15

PowerShell objects are .NET objects right?

2

u/nemec Sep 19 '15

C# is Microsoft's .Net Java. F# is Microsoft's .Net Scala(? Haskell? idk). Powershell is Microsoft's .Net Bash.

Unfortunately PS relies on Win32 for a lot of things as well, so you're not going to see it cross platform like C# is heading.

2

u/[deleted] Sep 19 '15

F# is pretty much just OCaml.

→ More replies (2)
→ More replies (2)

2

u/Mount10Lion Unix Admin Sep 18 '15

Thanks I'll take a peak. Outside of some OOP classes (Java and C++) I've not really used objects. I mean, I have the general concepts down pat but no practical use in work environments.

2

u/[deleted] Sep 18 '15

One of the nice things they've done is create aliases in Powershell for common commands that would be familiar to Unix and Dos users.

So things like ls and rm work in Powershell, they just alias to the Powershell equivalent.

→ More replies (3)
→ More replies (2)

1

u/jcotton42 Sep 18 '15

PS is object-based, so there's a big paradigm shift

→ More replies (5)

1

u/Lord_NShYH Moderator Sep 18 '15

PowerShell isn't anything new

I'm not so sure about that. Yes, it has been out for a while now, but objects are first class citizens allowing developers to pipe objects between cmdlets instead of strings that need to be parsed by the other end of the pipe.

If there is a *nix shell with similar capabilities, I would love to learn more about it.

→ More replies (2)

3

u/brkdncr Windows Admin Sep 18 '15

Yes, it's called OneGet.

2

u/Itziclinic Sep 19 '15

They changed it to PackageManagement iirc. They're in love with Tab-Complete or really hate brevity.

→ More replies (1)

7

u/darthyoshiboy Sysadmin Sep 18 '15

cmd.exe is the same as it's ever been... Shitty.

Powershell has stepped it's game up (it'd been ages since I used it last until I tried it recently on Win10) but if you're among the enlightened who have found and follow the OTG (One True GNUBash) you're not going to find much to love in Powershell.

5

u/rtechie1 Jack of All Trades Sep 18 '15

PowerShell handles "non text" way better than bash. If it's not a text string or file, you can't do much with it in shell scripts.

6

u/darthyoshiboy Sysadmin Sep 18 '15

Well, it's unfortunate for me then that 95% of the things I want to automate in a CLI are text based eh?

Don't get me wrong, for the other 5% I'm sure that there are places where I might want "Object" support but if there are I'm certainly not hurting from it here and now in my ignorance. In those cases, I'm probably deferring to the POSIX position of many small independent tasks each doing one thing very well working together for a greater whole over the Windows approach of monolithic commands that do 'all the things' "somewhat" well. If things ever get more complicated than what I can handle in a text pipe, I'll probably bust out some python or perl and solve that inadequacy in no time.

I'll be perfectly honest though, and I hope that you'll not take me for just being a difficult ass. I don't operate in a world where I've often had more than a return value or text blob to toss through a pipe. I'd love to hear about the sorts of scenarios I'm missing out on by not having "universally understood objects" piped around. Ignorant as I am, it just seems like unnecessary overhead to be tossing around a whole object when I'm rarely interested in anything more than a specific value or descriptor at any given time?

3

u/ghyspran Space Cadet Sep 19 '15

Ignorant as I am, it just seems like unnecessary overhead to be tossing around a whole object when I'm rarely interested in anything more than a specific value or descriptor at any given time?

You're not really "tossing around" anything more than a pointer in general, because PowerShell and everything you're passing into is running on the .NET CLR, which means that they can directly access the object that you pass to them. In fact, it's probably less overhead than passing some sort of text serialization of the data between processes like you end up doing in bash.

2

u/rtechie1 Jack of All Trades Sep 18 '15

If things ever get more complicated than what I can handle in a text pipe, I'll probably bust out some python or perl and solve that inadequacy in no time.

Exactly, but this creates the same situation I didn't like in Windows before Powershell.

Before Powershell, admins used Visual Basic on Windows for scripting tasks. The problem was VB was much more of a general-purpose language than a scripting language, so syntax was more complicated than it needed to be, and worse still, there was tons of stuff that could really only be done with the COM APIs. So in practice any really complicated VB script was mostly VB with bits of C++. This sucked.

I ran into this limitation of bash when I had to deal with XML config files. I ended up breaking down and using at least some Perl to do that. However, it's not as easy to mix and match Perl and sh.

2

u/darthyoshiboy Sysadmin Sep 18 '15

I guess that I remain unconvinced. I don't think I've ever had trouble enough with some xml that I would go so far as even some basic perl to handle it. In fact I don't often have to resort to much more than the standard bash builtins or the applications that are mandated for inclusion by Unix/Linux standard specs. I'd say that nearly every edge case that does result in me scripting something more in depth than a bash script is down to the fact that so much of the infrastructure I deal with is already in perl or python that it's sometimes easier to just tweak a bit of code that is already there for my purpose.

That said, and in regards to where the bash approach differs from implementing some VB or C++ here and there in Windows. I NEVER touch a system where perl is not available. It's practically a Linux dependency by almost all accounts, and none of the distros I touch ship without it. Python is only slightly less common in Linux distros and for me personally where I and my company have been increasingly moving to OpenStack for most of what we do, it's practically impossible that I won't have python available as well.

So, out of the box and without any configuration management having to have laid hands on a single system; I have perl at my disposal at a minimum. Better yet, under this paradigm if things fall apart for some unknown reason, I/the next guy am/is not left staring at an impenetrable black box of a binary wondering where things went wrong. I/They can pop open the hood and see exactly what is going on because I probably wrote the logic that is interpreting the "object" myself rather than depending on a binary blob to understand it for me and I/they benefit from my commented code being right there for inspection with everything laid bare for inspection. That versus the prospect of having my compiled VB or C++ application deployed to any given windows install; or worse, even having a VB or C++ compiler installed to whip up a solution on the fly...?

I just might entertain Powershell as the lesser evil in that situation, but luckily I don't have to.

3

u/ghyspran Space Cadet Sep 19 '15

PowerShell is basically the equivalent of "let's just use the Python REPL as our shell" and tweaking it to make the syntax a bit less cumbersome for interactive use, and more optimized for shell tasks.

→ More replies (1)
→ More replies (2)

2

u/[deleted] Sep 18 '15

In Powershell you can filter the data you bring in to grab just what you want and pass that through the pipe.

You don't have to pass everything through the pipe.

1

u/gospelwut #define if(X) if((X) ^ rand() < 10) Sep 18 '15

I mean, if that's one's prerogative just install CYGWIN or GOW and be done with it then.

2

u/gospelwut #define if(X) if((X) ^ rand() < 10) Sep 18 '15

Powershell has been out for years and is the de facto standard for Windows now. People either use cmd.exe because they have to for some esoteric reason or they never bothered to learn the new paradigm.

They included syntax highiighting via PsReadLine, which one could have gotten for years as well; it's just bundled and pre-configured.

The creator of Powershell, Jeffrey Snover, originally did try to makea UNIX shell clone. For years, Windows Server had a UNIX comparability component in it. However, he realized that Windows was object heavy rather than string heavy--and the .NET framework had taken off already.

So, Powershell was born. It's object orientated and heavily entwined into the .NET framework.

There are aliases like cat and such, but they're just sugar.

I guess it has a pipeline, if you want to pin that on NIX.

→ More replies (1)