Live data from Hacker News

A language that compiles to Bash and Windows Batch

github.com

101–110 of 148 posts

Re: A language that compiles to Bash and Windows Batch

#101

The idea is interesting, but ultimately the utility of this seems limited. The differences between windows and Unix are more than just the shell language involved; shell scripts are typically deeply intertwined with the system in question, to the point where it's often not the case that a bash script will even run reliably across different Unix systems, much less on windows. Also, you can already run bash on windows,…

The attraction for me is not about portability, it's about having a better language to write CMD script. Even when you know you have Python available sometimes you still need to glue things together with CMD.

These days you probably want Windows Powershell. It's built on the .NET framework so it's pretty darn powerful and AFAIK is available by default on every modern WinOS.

Re: A language that compiles to Bash and Windows Batch

#102
post #57
post #36

Earlier quoted context omitted.

I love python, but python is not a shell, and it makes an absolutely awful shell replacement. Python is further from a good shell than bash is from being a decent programming language. Some scripts are good, I do use python for some kinds of shell scripts, but most of what I need bash for, python is not a good replacement at all.

Perl is probably still the best in its class of being a decent language while allowing close interaction with shell commands. If I really needed to write a sophisticated shell script (try to avoid that), I'd probably go for Perl.

I'm mostly in agreement about Perl's status, but I'd rather take the small hit in verbosity for the niceness of the rest of Python rather than having to deal with Perl... Yeah it kind of sucks not having the backtick operator, but at least it's not too much of a hassle to do something like:

    from subprocess import check_output as sh
    files = sh(['ls'])
    print files
This has its limits but covers a lot of basic use-cases for the backtick. I think some people first see an alternate way of doing this in Python that's a lot more hairy, even if more flexible, but it doesn't have to be that way...

Re: A language that compiles to Bash and Windows Batch

#103
post #54
post #27

Weird that it doesn't seem to support basename (1) and dirname (1) and their Windows equivalents (e.g. %~dp0% ) Quite a few of my scripts need to find files relative to the location of the script, or compute the path to an output file by replacing the extension of an input file.

As I read it, it is mainly a language that intends to "unify" bash and batch, but basename(1) is not so much a part of bash, but of POSIX, that is an executable in a POSIX environment, that can be called via bash. However it does say "Batsh provided some "built-in" functions that will compile to platform-dependent code.". Arguably you could count basename and dirname under that.

The builtins are currently too limited. It looks like to get anything done you have to shell out to commands with call(), bash(), and batch() which leaves you with nice looking control structures surrounding a whole bunch of conditional code tailored for each platform. Path manipulation is an important missing feature. Some sort of array handling and filtering/sorting also needs to be abstracted.

Re: A language that compiles to Bash and Windows Batch

#104
post #96

Earlier quoted context omitted.

It's not about can or can't I think. Examples: Language runtime can't be installed, system locked down with deepfreeze, not enough permissions..

Then how will batsh get installed?

Isn't the entire premise of batsh that it compiles to bat?

Why would you need to install batsh?

Re: A language that compiles to Bash and Windows Batch

#105
post #97

Earlier quoted context omitted.

I don't use windows much anymore so there might be a better way to do this, but I'll propose a use case: Automating the installation of python on a fresh machine.

Fresh machine where and for whom? I doubt a simple batch script will get you very far (setup.exe exists for a reason...), and I doubly-doubt you would have enough overlap in the process that something that can convert the steps to bash would be an advantage. The only advantage I see for batsh is that it looks nicer to write in for the tiny subset of batch it supports. But then so is pretty much anything else -- it wo…

[deleted]

Re: A language that compiles to Bash and Windows Batch

#106
post #97

Earlier quoted context omitted.

I don't use windows much anymore so there might be a better way to do this, but I'll propose a use case: Automating the installation of python on a fresh machine.

Fresh machine where and for whom? I doubt a simple batch script will get you very far (setup.exe exists for a reason...), and I doubly-doubt you would have enough overlap in the process that something that can convert the steps to bash would be an advantage. The only advantage I see for batsh is that it looks nicer to write in for the tiny subset of batch it supports. But then so is pretty much anything else -- it wo…

Ok, I'll try another use case: Political differences (specifically licensing). This project appears to be licensed under MIT, and python appears to be licensed under !MIT. I don't know what the implications are for the licensing of machine-produced shell code, or binary versions of Python, but I'm sure there are companies out there that would have opinions to favour one alternative over the other for reasons other than the technical merits of the choice.

Re: A language that compiles to Bash and Windows Batch

#107

The idea is interesting, but ultimately the utility of this seems limited. The differences between windows and Unix are more than just the shell language involved; shell scripts are typically deeply intertwined with the system in question, to the point where it's often not the case that a bash script will even run reliably across different Unix systems, much less on windows. Also, you can already run bash on windows,…

I loved the idea.

Some years ago, I was making a project that many parts of the build process depended on simple file copies (that this can do right) and ImageMagik calls (that are the same in all OSes)

I ended having to keep writing the same scripts over and over again in Batch and Bash, it was quite a pain to maintain, and it was obvious that there had to be some way to do it automatically (port one to the other, or generate both).

This software has my situation as the perfect use case, when you need to script command line tools that exist in both platforms.

Re: A language that compiles to Bash and Windows Batch

#109
post #74

Earlier quoted context omitted.

The attraction for me is not about portability, it's about having a better language to write CMD script. Even when you know you have Python available sometimes you still need to glue things together with CMD.

> sometimes you still need to glue things together with CMD why? is there something cmd can do that python can't? one example is enough...

Who cares if Python can technically do it? If you have a CLI tool based around Bash, why would you want to rewrite it in Python and have to support it yourself and spend those man hours doing it?

Re: A language that compiles to Bash and Windows Batch

#110

Earlier quoted context omitted.

The attraction for me is not about portability, it's about having a better language to write CMD script. Even when you know you have Python available sometimes you still need to glue things together with CMD.

These days you probably want Windows Powershell. It's built on the .NET framework so it's pretty darn powerful and AFAIK is available by default on every modern WinOS.

Powershell _is_ great (I help run an OSS project written in Powershell), but it has a long start-up time. If you're doing it as a pre-build step for example, you don't want to add potentially seconds (!) to your build just to use powershell.
Post reply on HN