TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Bish – Shell scripting with a modern feel

84 pointsby bishcabout 10 years ago

17 comments

aidanhsabout 10 years ago
For a long time I couldn&#x27;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>&gt; The whole point of short code is saving human bandwidth, which is the single thing in a computing environment that doesn&#x27;t obey Moore&#x27;s law and doesn&#x27;t double once in 18 months. Now, which kind of bandwidth is the most valuable? I&#x27;ll tell you which. It&#x27;s the interactive command bandwidth.<p>It makes the argument that syntax is actually really important in building an interactive language - &#x27;[]&#x27; is better than &#x27;()&#x27;, &#x27; &#x27; is better than &#x27;,&#x27;. And it&#x27;s true, bash (and, as it happens, tcl) ruthlessly pursue this - strings don&#x27;t require quotes, function calls just require spaces (rather than brackets and commas) and there&#x27;s generally very little punctuation for the most common operations.<p>I bring this up because it&#x27;s interesting to see bish has gone in the other direction (curly braces, semicolons, brackets, quoted strings) in the name of a &#x27;modern feel&#x27;. It makes me wonder if there&#x27;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:&#x2F;&#x2F;yosefk.com&#x2F;blog&#x2F;i-cant-believe-im-praising-tcl.html</a>
评论 #9167438 未加载
评论 #9168518 未加载
评论 #9168840 未加载
评论 #9167098 未加载
评论 #9167099 未加载
alphapapaabout 10 years ago
I think that this may be unnecessary given the existence of the sh[1] Python module. It&#x27;s incredibly simple and concise, e.g.:<p><pre><code> from sh import date, ls, egrep, git print date(), ls(&#x27;~&#x2F;project&#x27;) print egrep(ls(&#x27;~&#x2F;project&#x27;), &#x27;-o&#x27;, &#x27;\.py$&#x27;) print git.add(egrep(ls(&#x27;~&#x2F;project&#x27;), &#x27;-o&#x27;, &#x27;\.py$&#x27;)) </code></pre> [1] <a href="http://amoffat.github.io/sh/" rel="nofollow">http:&#x2F;&#x2F;amoffat.github.io&#x2F;sh&#x2F;</a>
SwellJoeabout 10 years ago
Perl started with roughly the same goal. awk, sed, grep, etc. weren&#x27;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&#x27;t think this improves on Perl. Being compiled to Bash <i>might</i> be interesting, if your deployment systems don&#x27;t have Perl. It used to be unthinkable that any UNIX&#x2F;Linux system wouldn&#x27;t have Perl...but, several distros no longer install Perl by default (which is annoying as hell, to me, as Python isn&#x27;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&#x27;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&#x27;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.
评论 #9167847 未加载
评论 #9168588 未加载
wz1000about 10 years ago
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:&#x2F;&#x2F;github.com&#x2F;chrisdone&#x2F;hell</a><p>[1]: <a href="https://github.com/yesodweb/Shelly.hs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;yesodweb&#x2F;Shelly.hs</a>
mhwabout 10 years ago
Recently I&#x27;ve returned to writing scripts using Byron Rakitzis&#x27; reimplementation of the Plan 9 rc shell, and been very happy with the results. It doesn&#x27;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&#x27;t have to remember hacks like &#x27;&quot;$*&quot;&#x27;, 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 &#x27;proper&#x27; 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&#x27;s included in the standard Ubuntu repositories (<a href="http://packages.ubuntu.com/trusty/shells/rc" rel="nofollow">http:&#x2F;&#x2F;packages.ubuntu.com&#x2F;trusty&#x2F;shells&#x2F;rc</a>) and it looks like it&#x27;s in homebrew as well. I&#x27;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&#x27; version made some minor changes to the syntax (a more usual if...else instead of Duff&#x27;s &#x27;if not&#x27;) and dropped some Plan 9 specific pieces.
jkotabout 10 years ago
Why not fish (friendly interactive shell)?
评论 #9166689 未加载
awadabout 10 years ago
Was &quot;bish&quot; intentional? <a href="http://www.urbandictionary.com/define.php?term=bish" rel="nofollow">http:&#x2F;&#x2F;www.urbandictionary.com&#x2F;define.php?term=bish</a>
allendoerferabout 10 years ago
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.
basdpabout 10 years ago
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(&quot;Files in current directory $dir:&quot;);<p>printall(files);<p>cd(&quot;&#x2F;&quot;);<p>files = ls();<p>print(&quot;Files in root directory:&quot;);<p>printall(files);<p>Whats wrong with this, much shorter Bash sequence:<p>echo Files in current directory `pwd`:<p>ls<p>cd &#x2F;<p>echo Files in root directory:<p>ls
评论 #9166851 未加载
评论 #9166810 未加载
评论 #9166858 未加载
lihaoyiabout 10 years ago
Ammonite <a href="http://lihaoyi.github.io/Ammonite/#Ammonite-Ops" rel="nofollow">http:&#x2F;&#x2F;lihaoyi.github.io&#x2F;Ammonite&#x2F;#Ammonite-Ops</a> provides a similar thing for Scala
colechristensenabout 10 years ago
A definite case of <a href="http://xkcd.com/927/" rel="nofollow">http:&#x2F;&#x2F;xkcd.com&#x2F;927&#x2F;</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&#x27;s time, even if the product doesn&#x27;t change the world forever :)
zwischenzugabout 10 years ago
Available as a docker image:<p><pre><code> $ docker run -ti imiell&#x2F;sd_bish &#x2F;bin&#x2F;bash bash-4.3# bish USAGE: bish &lt;INPUT&gt; Compiles Bish file &lt;INPUT&gt; to bash. </code></pre> Magic here:<p><a href="https://github.com/ianmiell/shutit-distro/blob/master/bish/bish.py#L14" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ianmiell&#x2F;shutit-distro&#x2F;blob&#x2F;master&#x2F;bish&#x2F;b...</a><p>Note I needed to hack the code a little.
bkeroackabout 10 years ago
Great idea and looks like a good implementation. Are there native hashmaps and arrays? Those are things I like from Powershell.
iso8859-1about 10 years ago
How does this compare to candidates like Batch named here:<p><a href="http://stackoverflow.com/q/10239235/309483" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;q&#x2F;10239235&#x2F;309483</a> ?
dserodioabout 10 years ago
Starting a new project in C++ in 2015? Why not Go, Rust, or any compiled, memory-safe language for systems programming?
iso8859-1about 10 years ago
I feel like Bash is a very limiting language to compile to, because you cannot store the null byte in a (byte)string.
__michaelgabout 10 years ago
Why?
评论 #9167104 未加载