For a long time I couldn't figure out why moving from bash to Python felt like such a big leap, and it was quite frustrating (path manipulation is particularly difficult).<p>Recently I discovered a post [1] which touches on this:<p>> The whole point of short code is saving human bandwidth, which is the single thing in a computing environment that doesn't obey Moore's law and doesn't double once in 18 months. Now, which kind of bandwidth is the most valuable? I'll tell you which. It's the interactive command bandwidth.<p>It makes the argument that syntax is actually really important in building an interactive language - '[]' is better than '()', ' ' is better than ','. And it's true, bash (and, as it happens, tcl) ruthlessly pursue this - strings don't require quotes, function calls just require spaces (rather than brackets and commas) and there's generally very little punctuation for the most common operations.<p>I bring this up because it's interesting to see bish has gone in the other direction (curly braces, semicolons, brackets, quoted strings) in the name of a 'modern feel'. It makes me wonder if there's a way to bring the power of python (etc) into the shell in a syntax-friendly way.<p>[1] <a href="http://yosefk.com/blog/i-cant-believe-im-praising-tcl.html" rel="nofollow">http://yosefk.com/blog/i-cant-believe-im-praising-tcl.html</a>
I think that this may be unnecessary given the existence of the sh[1] Python module. It's incredibly simple and concise, e.g.:<p><pre><code> from sh import date, ls, egrep, git
print date(), ls('~/project')
print egrep(ls('~/project'), '-o', '\.py$')
print git.add(egrep(ls('~/project'), '-o', '\.py$'))
</code></pre>
[1] <a href="http://amoffat.github.io/sh/" rel="nofollow">http://amoffat.github.io/sh/</a>
Perl started with roughly the same goal. awk, sed, grep, etc. weren't quite powerful enough, C was too low-level, Perl mixed them all up with real programming language features, while still being very usable in one-liners.<p>I don't think this improves on Perl. Being compiled to Bash <i>might</i> be interesting, if your deployment systems don't have Perl. It used to be unthinkable that any UNIX/Linux system wouldn't have Perl...but, several distros no longer install Perl by default (which is annoying as hell, to me, as Python isn't at all an acceptable substitute for one-liners and shell+ tasks). But, in that case, it would need to compile down to POSIX shell, because Ubuntu doesn't install bash by default, it uses ash (a small POSIX shell). So, bash has the exact same flaw as Perl for that use case.<p>Anyway, I don't generally think this adds things that I wish for when working with shell scripting, and having to compile it (even a quick compilation like this is likely to be) takes away one of the biggest benefits of scripting languages.
Hell and Shelly are based on a similar concept, but also try to use the power of the Haskell type system to prevent common errors and bugs.<p>[0]: <a href="https://github.com/chrisdone/hell" rel="nofollow">https://github.com/chrisdone/hell</a><p>[1]: <a href="https://github.com/yesodweb/Shelly.hs" rel="nofollow">https://github.com/yesodweb/Shelly.hs</a>
Recently I've returned to writing scripts using Byron Rakitzis' reimplementation of the Plan 9 rc shell, and been very happy with the results. It doesn't have the idiosyncrasies that bash has, and which seem to be a motivation for bish. Variables are not rescanned when expanded so you don't have to remember hacks like '"$*"', for example. At the same time it adds some features which really help when writing scripts (a list type and a pattern matching operator for example). And yet it still feels like a shell rather than a 'proper' scripting language: pipes and redirection are still core parts of the language rather than things you have to program using the standard library.<p>It's included in the standard Ubuntu repositories (<a href="http://packages.ubuntu.com/trusty/shells/rc" rel="nofollow">http://packages.ubuntu.com/trusty/shells/rc</a>) and it looks like it's in homebrew as well. I'd recommend giving it a try. The original Plan 9 paper describing rc is a good place to start and a good read, although you should be aware that Rakitzis' version made some minor changes to the syntax (a more usual if...else instead of Duff's 'if not') and dropped some Plan 9 specific pieces.
As someone, who just recently started writing some small bash scripts, I wonder, why they did not create a universal comparator syntax and letting null, not-existing etc. evaluate to false, on top of the existing syntax. I get that it evolved, but since I did not evolve with it, I get frustrated by constantly tripping up on if-syntax, something you normally do not have to worry about when moving to other languages.<p>Bash hurts my ego.
def printall(files) {<p><pre><code> for (f in files) {
print(f);
}
</code></pre>
}<p># cwd, ls, and cd are all builtin functions.<p>dir = cwd();<p>files = ls();<p>print("Files in current directory $dir:");<p>printall(files);<p>cd("/");<p>files = ls();<p>print("Files in root directory:");<p>printall(files);<p>Whats wrong with this, much shorter Bash sequence:<p>echo Files in current directory `pwd`:<p>ls<p>cd /<p>echo Files in root directory:<p>ls
Ammonite <a href="http://lihaoyi.github.io/Ammonite/#Ammonite-Ops" rel="nofollow">http://lihaoyi.github.io/Ammonite/#Ammonite-Ops</a> provides a similar thing for Scala
A definite case of <a href="http://xkcd.com/927/" rel="nofollow">http://xkcd.com/927/</a><p>If you want to replace bash (in an environment where Perl, Python, and Ruby all exist in a space for more advanced scripting) you have to do a hell of a lot to improve on the existing standards.<p>Then again, a fun weekend project playing with compilers is a valid use of one's time, even if the product doesn't change the world forever :)
Available as a docker image:<p><pre><code> $ docker run -ti imiell/sd_bish /bin/bash
bash-4.3# bish
USAGE: bish <INPUT>
Compiles Bish file <INPUT> to bash.
</code></pre>
Magic here:<p><a href="https://github.com/ianmiell/shutit-distro/blob/master/bish/bish.py#L14" rel="nofollow">https://github.com/ianmiell/shutit-distro/blob/master/bish/b...</a><p>Note I needed to hack the code a little.
How does this compare to candidates like Batch named here:<p><a href="http://stackoverflow.com/q/10239235/309483" rel="nofollow">http://stackoverflow.com/q/10239235/309483</a> ?