11 ms·
A language that compiles to Bash and Windows Batch
- zwieback 10y agoLooks nice but wouldn't you just use something like Python nowadays?
- thoth 10y agoThe "Why not Python/Ruby/Node.js/Lua" section lists 3 reasons the author developed this language...
- sigjuice 10y agoBullet 1 says "None of them is preinstalled on all platforms", but OPAM isn't universally preinstalled either.
- recursive 10y agoYou can build your scripts to a machine that has OPAM and distribute them to one that doesn't.
- merb 10y agoOPAM is only needed on the computer you develop the script. Actually you guys shouldn't be so lazy to just write something without reading the README.
- ake1 10y agobut you don't need opam to run the compiled scripts...
- hk__2 10y agoThe second point says “Functionalities like process piping are not convenient to use” but Batsh itself doesn’t support piping [1], a core feature of shell languages. [1]: https://github.com/BYVoid/Batsh/issues/17 https://github.com/BYVoid/Batsh/issues/17
- onecooldev24 10y agoI don't think windows comes with python installation.
- Jach 10y agoIt also doesn't come with any of the tools bash is a glue for, about the only reason one uses bash. At least with Python I can write my own grep and so on, and piping isn't so bad with coroutines and generators.
- scott_s 10y agoI think you missed the point of this language. You write code in this language, and then you compile it to get Bash for Linux and Batch for Windows.
- Jach 10y agoI get it, I just disagree with "it's not bundled" as a major disadvantage: neither is your script, and maybe neither is your argument to any `call()`, so you're going to be thinking about deployment in any case.
- catmanjan 10y agoCould be a great tool for government/enterprise customers who want to avoid the whitelisting process involved around getting anything installed. IT departments would laugh at you if you said you wanted to install python on their server...
- Jach 10y agoSure, there are probably use cases, though I'm biased to think there are better options for any specific one except perhaps the project creator's inspiring situation. IT can laugh, I laugh back when java/flash/excel/browsers are already installed.
- milcron 10y ago
- deleted 10y ago[deleted]
- dahart 10y agoI 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.
- moondev 10y agoBut the goal of this is not shell replacement correct? It is a way to write scripts for both platforms. Python has great cross-platform support in that regard: http://hplgit.github.io/edu/ostasks/._ostasks002.html http://hplgit.github.io/edu/ostasks/._ostasks002.html
- dahart 10y agoYes, you're right. Batsh isn't trying to be a shell replacement, but it is targeting the two shells that you're nearly guaranteed to find one of on any given computer. I dunno if @zwieback was saying Batsh should target python, or if people should use python instead of Batsh, or something else, but neither of those first two suggestions makes a lot of sense to me. Python's decent cross platform support doesn't really make it better for shell scripts, and while I use it for some shell scripts, I don't ever default to python. My comment was reacting to the "wouldn't you just", as though python is a natural default choice. In my experience, it's not a good default choice. It's harder to debug python shell scripts, because you typically can't run individual lines, you typically can't cut and paste parts of it, you can't ever run system commands directly without wrapping it in a python module call, output might not display automatically, and you often have to install something that isn't already on the machine.
- TillE 10y agoPerl 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.
- 10y ago
- kazinator 10y agoWhat if you want to build Python? Oh, that' easy, you unpack the Python sources and start with: ./configure But what is that? It's not written in Python. It can't be, because you don't have Python yet. It's a shell script. It's not a hand-maintained shell script; it's written by expanding Autoconf macros (in the M4 preprocessing language) to shell code: essentially a compiler from another language to shell. A cleaner language which does the same thing could, in principle, replace Autoconf. A related use for such a language would be install scripts: perform complex actions to install some software, with minimal dependencies on what is already installed.
- MichaelBurge 10y agoWriting your language's build system in itself shouldn't be any worse than writing your language's compiler in itself. The GHC folks are rewriting their jungle of recursive Makefiles in Shake, a Haskell-based build system. I think you only need the ability to build a cross compiler for this to work.
- scandox 10y agoYou've got to admire this and at the same time you can't help but see the shadow of two more letters on the end of its name...
- angersock 10y agoAdopted by ASF as Apache Guano(tm).
- mfb2 10y agoPlease give this person a medal.
- deleted 10y ago[deleted]
- ArkyBeagle 10y agoThe colonel interface is called 'bat' Guano, but then you have to answer to the Coca-Cola company.
- hughw 10y agoDon't script it. Batsh it!
- dragontamer 10y agoWhat about... lets take a "Shtab" at the problem.
- bjohnso5 10y agoI feel like it was created just to make this sentence possible. Love it!
- monocasa 10y agoThat's not a bug; it's a feature.
- xrstf 10y agoIs there a way to get this as a precompiled Windows binary? I really want to give this a try, but I'm just sooo lazy and don't want to install OPAM if there's maybe a way around that.
- maxerickson 10y agoIf you just want to fool around there is a converter on the website.
- zem 10y agoironically, the instructions there don't tell you how to get opam installed on windows either. i don't know the answer, but apparently [it's not trivial](https://github.com/ocaml/opam/issues/246 https://github.com/ocaml/opam/issues/246)
- pm 10y agoWas hoping the website was a .it domain.
- legacy2013 10y agoThis is cool, but I hope the new Linux Subsystem in Windows 10 will propagate enough that everything can be written in bash
- tk32 10y agoi will never understand why people fetishize that awful language.
- consto 10y agoIt's significantly better than batch
- criddell 10y agoWell sure, but these days PowerShell is what Windows people use for anything non-trivial.
- nopreserveroot 10y agoIt is significantly better than PowerShell.
- criddell 10y agoand significantly worse too.
- deleted 10y ago[deleted]
- consto 10y agoReally? I though PowerShell was designed primarily to replace cmd. Surely Windows people use actual programming languages for the majority of tasks with PowerShell/cmd for smaller scripting tasks.
- wvenable 10y ago
- jtwebman 10y agoThe project hasn't been worked on in over a year also it isn't the language that is much different but the tools. Are you going to write grep on windows? If not the language really doesn't matter.
- preordained 10y agoAgree, you have to be careful these days not to bet on a dead horse. Or healthy and promising initially, but swiftly dead. I don't know that I need grep on windows or other powerful nix tools to find value in this. I'm not going to get cross-platform powerful scripts, but I need some simple batch file on windows to something, and god forbid I need to loop or increment or something, I'd probably rather use Jim's home brew language than batch...cuz it's that painful.
- alkonaut 10y agoIf the language has a string search command then it can implement its own, or it can delegate to grep on Linux and Findstr on Windows. Obviously in both cases it can't cover all that grep can do, but that likely isn't in scope. All I'd want is a tool that lets me maintain one build script for example.
- marshray 10y agoI was yearning for something like this literally just last night. Still am, tempted to give it a try.
- juped 10y agoExcellent idea. The only thing I thought was "why not PowerShell", but XP compatibility is probably the reason. (It exists but isn't preinstalled for that version.)
- badloginagain 10y agoPowershell versioning is also a nightmare
- Someone 10y agoWeird 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.
- RGamma 10y agoAs 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.
- kevin_thibedeau 10y agoThe 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.
- onedognight 10y agoI was disappointed to see that the compiler was not written in batsh and therefore not self hosting. Seems like a missed opportunity.
- exabrial 10y ago"Bash is the assembly code of Unix?"
- eagsalazar2 10y agoI've never tried but can't you already just run your node or ruby or whatever scripts on both Windows, Mac, Linux? Is there some reason targeting bash and batch is important?
- ygra 10y agoBoth tend to exist on their respective operating systems by default, making it something that can run without further dependencies.
- laported 10y agoFrom the README: Why not Python/Ruby/Node.js/Lua Yes you can use any of them as platform-independent glue code. But there are several disadvantages: None of them is preinstalled on all platforms (including Windows). Functionalities like process piping are not convenient to use. Hard to integrate with existing code written in Bash or Batch. Those reasons are why I developed Batsh.
- chris_wot 10y agoI love the fact that someone, somewhere needed this, and then someone, somewhere created it.
- eggy 10y agoMe too. He created it at a Hackathon, it gets posted to Hacker News, and people here are still asking why. Because...
- sedatk 10y ago@echo off set java=/usr/bin/java that's not how it works. that's not how any of this works.
- _quick_q 10y agoWhere are you finding that?
- moondev 10y agoSince docker is on windows now, this should run script.sh in current directory pretty easily. docker run -v %CD%:/opt -w /opt debian:jessie ./script.sh
- thinkpad20 10y agoThe 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, so once again the problem doesn't seem to be the language per se. I can only imagine how difficult it would be not just to design a script that would work properly on both platforms, but to debug the cases where it didn't. Also, as others have noted this language doesn't support redirection, which in my mind makes it practically useless beyond toy applications. I've written hundreds of bash scripts and I don't think any of them didn't make heavy use of pipes and redirection. I'm also not sure if the language supports running processes in the background, traps, magic variables like $!, extra options, subshells, file globbing, etc, all things that many real-world scripts use. Bash scripts often use many programs available on Unix systems as well, such as find, grep, readlink, xargs, and other things that aren't part of the language per se. Unless those are ported over too, writing useful scripts would be almost impossible. Finally, I don't think the author has made a convincing argument that such a language is even needed, when languages like perl/python/ruby exist for when the task is complex enough to require a more powerful language. On the other hand, if the project is (as I suspect) purely for fun and interest, then by all means :)
- badloginagain 10y agoI think it's a limitation more on the windows batch end. As mentioned, it's tricky for historical reasons. Powershell would be closer to Bash, functionally speaking. An adapter between the two would be more functional- however doesn't satisfy the point of batsh, which assumes cleanish-builds of the OS in question.
- stephengillie 10y agoPowershell introduces more complications, with functions like Invoke-WebRequest being given the alias "curl". At a minimum, you would get a type validation error, as Invoke-WebRequest by default gives back headers and other data as objects inside a larger object, not just the content string that curl.exe defaults to returning. This should work in both bash and PS, with different results: > curl HTTP://example.com > file.html
- tomcam 10y agoI must have done it wrong. In the late 80s, I created a Windows batch-to-executable compiler called Builder (extending the language greatly, to the point of menus as language constructs). Made a decent living off it, too!
- bbcbasic 10y agoConsider posting in here then: https://news.ycombinator.com/item?id=11718197 https://news.ycombinator.com/item?id=11718197
- evincarofautumn 10y agoHow should I pronounce the name? I read “batsh” as a homophone for “batch” [bæʧ], which is unfortunate. Is it supposed to be pronounced as two syllables [bæɂ.ʃ] or something like that?
- bbcbasic 10y agoPronounced "bath". The s is silent.
- jheriko 10y agohow is this top item? seems unfinished, unpolished, not very useful and very run of the mill as an achievement. no easily found windows installer and has obscure dependencies whilst claiming it has none etc. etc.
- sixothree 10y agoI don't even see the ability to iterate through files or am I missing something?
- nikolay 10y agoI posted Batsh long ago, but it's totally impractical. The multiplatform PowerShell is the best option. Anyway, we need a new shell and NGS [0] looks like it. Neither zsh, nor Fish offer what a shell scripting language needs so that you don't have to use Python, Go, or another language for a slightly more complex stuff! [0]: https://news.ycombinator.com/item?id=11734622 https://news.ycombinator.com/item?id=11734622
- BYVoid 10y agoI am the author of Batsh. Batsh is a toy language I developed 2.5 years ago in a hackathon. It was just for me to play with OCaml. Feel free to play with it at http://batsh.org/ http://batsh.org/.
- asimuvPR 10y agoIt's a pretty interesting idea, more so when developed under the context of of a hackathon. Where did the idea come from?
- xyience 10y agoThis deserves to be called out in the readme, if for nothing else than to limit the wild threads on display here and maybe head off some future wild threads.
- onecooldev24 10y agoHey man this is cool, I posted this for you on hacker news.
- BYVoid 10y agoI am the author of Batsh. Batsh is a toy language I developed 2.5 years ago in a hackathon. It was just for me to play with OCaml. Feel free to play with it at http://batsh.org/ http://batsh.org/.
- incepted 10y agoIsn't it ironic to write this tool in a language that is not available on Windows[1]? [1] "Windows support is comming soon. " https://ocaml.org/docs/install.html https://ocaml.org/docs/install.html
- nv-vn 10y agoOCaml is available on top of MinGW or Cygwin. The thing that isn't supported is OPAM (the package manager), and that's only for official support -- if you compile with MinGW or Cygwin you can get it working well enough for most tasks. You can actually get the compiler binaries from a precompiled versoin of the official distribution[1] or from a user-maintained distribution[2]. Additionally, you could just compile everything from source but that's more complex. [1] https://protz.github.io/ocaml-installer/ https://protz.github.io/ocaml-installer/ [2] https://www.typerex.org/ocpwin.html https://www.typerex.org/ocpwin.html
- kelvin0 10y agoCool stuff! Would have been useful for me when all I knew was C++! Unfortunately, I use Python for exactly this type of scripting. Oh and I also use it for stuff like Django, lxml, requests, wxPython, OpenCV, PyGame, NumPy, Reportlab ...
- knocte 10y agoAt the time GNU/Windows became a thing recently (https://msdn.microsoft.com/en-us/commandline/wsl/about https://msdn.microsoft.com/en-us/commandline/wsl/about), the idea of Batsch turned obsolete to me. And anyway I have been already been using crossplatform .fsx scripts for quite some time. KTHXBYE
- fpoling 10y agoI like the idea of compiling to bash from a much saner language even without Windows compatibility. With containers and slimmed-down OS like CoreOS Python and friends may not be available. Besides, for some tasks Python startup time is just unacceptable so using Bash could be a good option if not the awkward syntax to put it mildly.
- youjiuzhifeng 10y agoCygwin provides another way to run the bash shell on windows. It is really helpful with full features of some commands like 'find' 'sed' 'awk'.
- ricksplat 10y agoA couple of slight nitpicks, but isn't this more like a translator? I understand a "compiler" to be that which condenses high-level structures down to more fundamental CPU-oriented structures (as opposed to an "interpreter" that takes the structures as presented). If you're compiling into Bash, or windows batch then you're converting from one high-level representation into another. Though you could debate whether these are "high level" whether they are technically or not. I will concede that this batsh language does indeed look a lot nicer than either - it seems to be of the "general purpose" style of C or Javascript rather than the more targeted style of either bash or batch - which is specifically for the domain of operating system scripting - I guess this might mean it's actually lower level. The whole thing is pretty cool though :-)
- emmelaich 10y agoThis would be a candidate for the scripting language in redo Paging @apenwarr
- agjmills 10y agoRelevant XKCD: https://xkcd.com/927/ https://xkcd.com/927/
- niutech 10y agoThere is also Pash: PowerShell + Bash (http://pash.sourceforge.net http://pash.sourceforge.net)
- meunier 10y agoOpportunity to name this batshit wasted.