392 points · by onecooldev24 · 10y ago · 142 comments
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 :)
Even when you know you have Python available 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...
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.
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.
This should work in both bash and PS, with different results:
> curl HTTP://example.com > file.htmlcurl HTTP://example.com > file.html
and on PowerShell it'd become
(curl HTTP://example.com).Content > file.html
I agree its a crappy language, but remember, it's a shell, not a language. It serves a different purpose than being good for pure code, so saying something like "<your favorite scripting language here> is better than bash" doesn't hold a whole lot of water. It is way better than batch though.
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.
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.
docker run -v %CD%:/opt -w /opt debian:jessie ./script.sh
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.
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.
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.
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...grep = findstr
cat = type
which = where
sort = sort
more = more
sudo = runas
no easily found windows installer and has obscure dependencies whilst claiming it has none etc. etc.
[1] "Windows support is comming soon. " https://ocaml.org/docs/install.html
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. @echo off
set java=/usr/bin/java
that's not how it works. that's not how any of this works.And anyway I have been already been using crossplatform .fsx scripts for quite some time. KTHXBYE
Paging @apenwarr