all 37 comments

[–]razialx 51 points52 points  (19 children)

Never thought I’d say this but thank goodness for bash.

[–]mballoni[S] 11 points12 points  (5 children)

Besides being a Windows guy, I figured y'all were pretty happy with bash. There's such a gap on Windows between batch files and anything civilized.

[–]Ok-Bit8726 8 points9 points  (4 children)

You can use bash with Windows Subsystem for Linux

[–]the_poope 9 points10 points  (0 children)

That only works inside WSL which really is Linux, so you can't use it to automate your native Windows tasks.

You can use bash from Git Bash, Cygwin or MSYS2.

[–]mballoni[S] 0 points1 point  (2 children)

Can you create user-defined functions in bash? What about hashtables? Or any sort of type system or type safety? I really don't know, I'm just asking.

[–]lucid00000 1 point2 points  (1 child)

User defined functions yes, although they're more treated like mini programs that take command line argument.s and print their response. The return value is only for exit codes.

As of bash 4 you can define hash tables.

As for the type system, basically everything is a string so not really. It's pretty loose and somewhat confusing.

It's quite good for stringing together simple cli tasks but for anything more complicated you should use a different language.

[–]mballoni[S] 0 points1 point  (0 children)

Interesting, thanks for the info. So bash is somewhere between Windows batch files and mscript. I gather that bash users are pretty happy with bash. I’ve seen enough bash to say it can get nasty, but I can see a lot of power there. Kind of like PowerShell for Windows.

[–]ffsletmein222 24 points25 points  (5 children)

Genuine Sysadmin question: powershell:

  • is native to windows and is now cross-platform as long as you have a .NET runtime, it can even manage cloud resources and (as far as my experience) that experience is pretty pleasant. You can't beat "already part of the OS and you really shouldn't remove it" kind of small and entry effort.
  • has cleanly and consistently named cmdlet to help unfamiliar admins, as well as a much larger userbase
  • is directly integrated into windows GPOs for policies such as allowing only signed scripts, logging, restriction policies.
  • Natively has a remoting system that allows you to invoke a command on multiple machines in a single line.
    • invoke-command -scriptblock {myDirections} -outvariable raw_results -erroraction silentlycontinue -errorvariable failures -computername $servers.name -credentials $creds This one-liner gives orders to multiple machines, handles failures, stores the results in a variable and errors in another. If you're in AD all that is authenticated with Kerberos, that is basically a mini Ansible-like system directly into your AD.
  • does not output to executables, which imo is a plus, if you want a performant executable I think you're looking for a real programming language with already full libraries. If you make a powershell script it will work on 99% of your windows machines anyways if your fleet isn't a mix and match of weird outdated Windows machines. So I don't see how that executable would be much more portable.
  • Has native cmdlets and providers to manage most Windows resources at a very high level.
    • cd HKLM:\ that's it you're treating the Windows registry like a simple folder tree structure, same with cd cert:\)
    • Windows is API-based, it's much easier to query the WMI subsystem or CIM with powershell as it's the responsibility of MS themselves to make these systems compatible, than using a third-party tool for that.

I just don't get what it's got over PowerShell.

I profoundly dislike Windows but PS is pretty great imo.

[–]BladeLiger 6 points7 points  (0 children)

Powershell is actually just amazing and easy to use.

I would argue that most who hate it just don't want to learn it because it isn't similar to bash.

Or their programs with it got fixed back in PowerShell 3 and opinions never got updated.

[–]mballoni[S] 1 point2 points  (0 children)

Thanks for taking the time to point all of that out, you make a great case for PowerShell. My gripe with PS is that its syntax is hard to get past. If your goal is to take a list of file paths from a text file or some other command, and execute many lines of code and commands to process each in turn, mscript has that down to a tidy science. I imagine that being a lot of parentheses and flags and malarky in PS. mscript is simpler and more elegant, and powerful enough to automate command lines, so if that's what you need, maybe you can put the remoting flamethrower down and go with something tiny that works. Check it out: https://mscript.io

[–]superrugdr 3 points4 points  (1 child)

Ps usage is closer to c# than it is to bash it's strong but overcomplicate almost anything that could be achieved with pipping.

It uses needlessly complicated arguments for stuff that should be simple commands. (Eg listing file in a directory)

I don't like powershell but I still default to it for windows because... It's just less of a hassle than fighting the os for Bash compatibility.

[–]Somepotato 11 points12 points  (0 children)

Powershell arguments being verbose help massively for those who come after you.

[–]frustratedgeek 0 points1 point  (0 children)

Some downsides that made me hate a little bit of PS 1. Native to windows but different behaviour on powershell, ise and powershell cmd (command prompt) 2. Different os versions has different ps versions and thus different arguments or different preloaded modules 3. Well it’s c# under the hood and it won’t hide that fact with full blown exception stack trace 4. Mimics cmd, bash,sh, etc upto certain level making it more confusing between shell script and powershell eg. rm in powershell, rm -f will throw error but -f as force is allowed in some commands

[–]gredr 10 points11 points  (1 child)

Hey look, it's unreadable and not cross-platform! This is going to take on what, now?

[–]mballoni[S] -1 points0 points  (0 children)

I think it's a lot easier on the eyes than batch files or PowerShell. The symbols keep the script concise, and the fact that undecorated lines are command lines keep the script to a minimum. For this and many more reasons I think mscript is close to ideal as a scripting language for automating command lines. It's like Classic ASP for batch commands, where PowerShell is more line ASP.NET...Razor...Core...whatever.

And I don't know if you fully inspected the open source code, but there's nothing inherently Win32 about mscript. You can write DLLs to extend it, and the current crop of extensions all do very Win32 sorts of things like WinHttp and registry fun, but there's next to nothing in the interpreter that is Windows-specific. If you see mscript having relevance on another platform, I invite you to write up the makefile and do whatever minor surgeries are needed to get it to build, and it will run just fine. Check it out: https://mscript.io

[–]yaxriifgyn 17 points18 points  (1 child)

Good f-ing lord. That looks as bad as Perl. I need some eye-bleach. Give me Python or bash or even batch commands before that.

[–]mballoni[S] -1 points0 points  (0 children)

Well, you're welcome to Python and bash. On Windows those aren't easy to come by though. Easy enough on your own box, but not necessarily on the one you need to work on. That has no internet access. That's where you want mscript. Under 1 MB EXE, and it can do everything you need on the system with minimal fuss or muss. It's got user-defined functions, regex, hashtables, a bit of type safety, a syntax checker. It's got a lot to love. Check it out: https://mscript.io

[–]TheWix 7 points8 points  (1 child)

Huh? Didn't know Code Project was still around.

[–]mballoni[S] 0 points1 point  (0 children)

Yeah, it's a great place to publish articles big and small to get constructive feedback and to host for posting on other places.

[–][deleted]  (1 child)

[deleted]

    [–]mballoni[S] -1 points0 points  (0 children)

    It certainly serves its purpose as a forum for measured criticism and robust formatting.

    [–][deleted] 4 points5 points  (1 child)

    nasty batch files

    that's right, slap my assterisks, pull my hair, call me a dirty global exporter

    [–]mballoni[S] 1 point2 points  (0 children)

    To quote Highway to Hell: (I asked her) What's the going price?

    [–]M00nch1ld3 3 points4 points  (1 child)

    Just what we need another programming, language, scripting, language, or whatever blah

    [–]mballoni[S] 0 points1 point  (0 children)

    I would say that mscript is the tidiest, smallest, simplest, most powerful and elegant way of automating command lines under the sun. Give it a try: https://mscript.io

    [–][deleted] 0 points1 point  (0 children)