Live data from Hacker News

Batsh – A language that compiles to Bash and Windows Batch

batsh.org

111–120 of 130 posts

Re: Batsh – A language that compiles to Bash and Windows Batch

#111
post #80
post #76

Earlier quoted context omitted.

With PowerShell level of slowness it starts to matter. Even very basic commands seem to sometimes take many seconds to run. In the middle of intense workflow it becomes a problem.

Care to give examples? I know that the language isn't fast, but afaik nearly all shells are interpreted. There have been performance problems with break/continue in earlier versions as they were implemented using exceptions internally. But that doesn't really qualify as "basic commands", I guess. Cmdlets should be not much slower than running the equivalent C# code yourself.

Hmm, I can't seem to reproduce many such issues with this machine, except Get-Help the first time I tried it. I think it could be that the cmdlets are only slow on the first run (enough to leave me with a bad experience), or the SSD on my PC masks the problem. It's good to know that it's not always super slow.

Re: Batsh – A language that compiles to Bash and Windows Batch

#112
post #109
post #86

Earlier quoted context omitted.

You have that guarantee starting with Windows 7. Version is one thing; some nice things are available only in v3+, but v2 is very usable already. Execution policy is another matter, but you can always supply a batch file with the PowerShell script containing powershell -ExecutionPolicy Bypass -NoProfile -File %~dp0.ps1 %* That's what I usually do, which is also helpful for colleagues who have no idea how to run a Pow…

| You have that guarantee starting with Windows 7. Version is one thing; some nice things are available only in v3+, but v2 is very usable already. I love me some Powershell. Wrote my first non-trivial PS script in early 2010 that was a major component to building something I would now call "Continuous deployment of Windows OS images." But I still have way more lines of BAT in production than PS1 because the versioni…

This is not an example of evolving syntax. It's just a bunch of parameter sets added to Where-Object. New syntax is the -in operator for example (reverse of -contains).

However, I find myself using the new parameter sets for Where-Object very infrequently. Since they can only model

    Property -Operator Value
their use is limited to certain operations, which I find myself to need not that often. And if the conditions get more complex I need to write a scriptblock anyway, having to refactor your former form into the latter.

Re: Batsh – A language that compiles to Bash and Windows Batch

#113
post #72

This is great for me. As part of my day job I am often stuck writing batch scripts (yes, in 2014) for clients that refuse to run powershell. Writing a simple batch script is usually not a problem, but it can be very encumbering as the complexity increases. Thank you for sharing.

Is VBScript/JScript not an option? It should be on every machine you come into contact with.

The WSH can be disabled via group policies and often is.

Re: Batsh – A language that compiles to Bash and Windows Batch

#114
post #101

One peculiarity of batch files, and how cmd.exe executes them is that they are being read over and over (or maybe they are simply mapped file). I've found this by trial-and-error - while I was editing a batch file that was executing, it would suddenly error out with meaningless info, sometimes it'll print out the things I've just added to it.

This is actually true of bash as well (and has bitten me a few times).

Try this:

  $ echo 'echo hello; sleep 2' >/tmp/hm.sh; bash /tmp/hm.sh & (sleep 1; echo 'ls /bin' >>/tmp/hm.sh); sleep 3

Re: Batsh – A language that compiles to Bash and Windows Batch

#115
post #76

Earlier quoted context omitted.

This eludes me but why care about the performance of a shell scripting language?

With PowerShell level of slowness it starts to matter. Even very basic commands seem to sometimes take many seconds to run. In the middle of intense workflow it becomes a problem.

What could a shell possibly do so that a basic command would take many seconds?

Currently, "many seconds" is enough time to run an interpreter on the command, connect to a remote machine in Iceland, spin up a new virtual server there, send the command there to be executed, review the execution results for possible exceptions, run a malware scan, fetch the response back, execute the command again on your computer, translate the command and results to Klingon, send them to NSA for archiving, play a quick game of chess with another instance of the shell, and play a congratulatory tune.

Seriously, computers nowadays are fast enough to run a partial compile of your code at every single keystroke while you're writing it. It takes special effort to make a scripting language unusably slow - even an unoptimized interpreter that itself runs on a different interpreter should do just fine.

Re: Batsh – A language that compiles to Bash and Windows Batch

#116

So I like the idea of a cleaner higher level version of BASH that still works like BASH but doesn't have the baggage of it's evolution. Key feature has to be output that is no less readable than the average bash script. Which it seems to be.

Well, if someone wants a portable and a bit higher level version of shell scripts, then the classic answer for that is Perl.

Re: Batsh – A language that compiles to Bash and Windows Batch

#117
Speaking as a guy who runs an IT Management & Consulting org I can confirm that there is still a ton of XP in the market that needs support. For those this product could be a godsend.

For everything since XP though, I and my team strongly prefer PowerShell. Once you grasp the logic of PS it, in my opinion, crushes every other scripting language that has ever been native to Windows. We routinely pull in .NET libraries for third party software to automate them as well. And the out of the box WMI support makes system administration tasks a snap.

All that said, batch scripts are still absolutely needed for some purposes and applications. There is no way around that until the last XP and 2003 boxes go to the great window in the sky...

Re: Batsh – A language that compiles to Bash and Windows Batch

#119
post #4

This implementation is not perfect, although it's interesting that it supports Windows. I personally don't care about that, but it brings the idea to create some sugary wrapper around Bash that allows you to use Bash v4 features such as associative arrays in Bash v3, and wrappers that allow functions to return arrays and other typical headaches.

My initial thought after seeing this is Windows support is interesting, but the real value is in making bash friendlier. Something that brings syntactic sugar to bash is welcome in my mind, as I always find myself putzing with Google to find solutions to even slightly non-trivial scripts. Perhaps I should just master bash scripting once and for all (I know it's not that complex), but I generally find it unpleasant to…

>> A simple way to bootstrap the compiler with the script itself would be especially nice. Basically, an embedded batsh compiler. Might be an interesting avenue for an enterprising person to look into.

This could be very easy. If this can't be rigged with simple shell scripting (in a reasonable way), then it could with straightforward changes to the compiler (such as outputting to standard output). If you don't mind doing somewhat silly things like writing out scripts as temp files, this could certainly be done now.

Re: Batsh – A language that compiles to Bash and Windows Batch

#120
post #80

Earlier quoted context omitted.

Care to give examples? I know that the language isn't fast, but afaik nearly all shells are interpreted. There have been performance problems with break/continue in earlier versions as they were implemented using exceptions internally. But that doesn't really qualify as "basic commands", I guess. Cmdlets should be not much slower than running the equivalent C# code yourself.

Hmm, I can't seem to reproduce many such issues with this machine, except Get-Help the first time I tried it. I think it could be that the cmdlets are only slow on the first run (enough to leave me with a bad experience), or the SSD on my PC masks the problem. It's good to know that it's not always super slow.

If it's slow on the first run, then it might be loading a large interpreter from disk. If so, MS might have let the interpreter get a bit ungainly -- you might argue.
Post reply on HN