10 ms·
Bash Infinity: Standard library and boilerplate framework for Bash
- samat 8y agoVery cool from hacker perspective, but I'd ask 'why not use some of the languages you've mentioned, instead of inventing a new one?'
- chme 8y agoFascinating. Bash is a programming language you don't want to use, but end up using anyway. Any effort to make it a bit less clunky and maybe even a bit saver is welcome.
- hnzix 8y agoI was rockin' a fancy zsh config on my devbox until I started doing more ops work and traipsing around foreign servers. My muscle memory became useless and back to bash it was.
- themodelplumber 8y agoSame here with Fish
- Myrmornis 8y agoSame here with zsh. I switched my laptop shell to bash since working all the time in the interpreter at the shell prompt makes me better able to write bash scripts. I don't particular want to deal with the minor syntactic differences of zsh, or the totally different fish, seeing as I have to know bash well.
- tomc1985 8y agoI've never understood how people can insist on super fancy custom configs, it is so normal to burn through servers. Just learn the defaults, life is way easier...
- TeMPOraL 8y agoIt is so normal for sysadmins. Not for developers. Maybe it's more normal now, but that's a recent development. (These days, I hope I can just develop my super fancy Emacs config in one place, and use TRAMP to work with remote machines through an environment customized for me.)
- tomc1985 8y agoThroughout my career in dev I have always had to have a presence on sometimes dozens of servers. If something can't be fully customized in a few keystrokes it is not worth the effort, especially if whatever is being customized gets thrown away.
- oblio 8y agoYou'd be surprised how different dev careers can be. In Windows land it's quite frequent that the dev never leaves Visual Studio. In Eclipse/Java land something similar, even though often the deployments would be on Linux, for cost saving reasons, the devs would all be on Windows. I should write a blog post or something at some point about the differences in dev careers. Enterprise software development is very different from embedded software development which is different from web development for the mass market which is different from mobile development, etc.
- leksak 8y agoLink it here
- mxuribe 8y agoI would look forward to your blog post! Seems an interesting topic.
- bradknowles 8y agoAnd then those Java developers have to try to interface their code to Jenkins to get it to do CI, and the sysadmins have to deal with the Java guys who just click on the "Run" button in Eclipse and don't know basic things like what directory the code needs to execute from. Don't get me wrong, those Java developers can be great guys, but when the GUI-only people have to interact with the CLI for the first time, all sorts of problems can manifest themselves.
- Symbiote 8y agoI'm considering adding Zsh to the base install of all my servers, since it's so useful to be able to write a script with something like *(om[1]) for the most-recently-modified file, or $i:l to get a variable in lower case. I do deploy a .bashrc with some shell aliases, which are the most annoying things to miss when I'm used to using them locally.
- kevan 8y agoI try to avoid writing bash scripts so I hopefully won't use this, but it looks a very well thought out piece of software. Fantastic readme with rationale and examples for every feature.
- gjstein 8y agoI suppose I only use Bash infrequently, but when I do it is normally in an effort to make scripts that I know will run on my various machines for data processing and the like. I am hesitant to use a framework like this (as exciting as it seems) because I fear it would mean managing more dependencies across my different development machines. What are people using Bash for that would require enough complexity that a framework like this becomes a godsend? Edit: typos.
- unixhero 8y agoBuilding things. It comes with logging and unit testing. What's not to like. There are a lot of people who does not know any other languages, believe it or not.
- nerflad 8y ago> There are a lot of people who does not know any other languages, believe it or not. This is the only reason I can see to use this over perl (which it seems to be heavily influenced by) or python. Then again, learning how to use these higher level language features would probably require equivalent effort to just learning a beefier scripting lang such as those. Also: As far as hack value, what a great project. I don't mean to bikeshed.
- User23 8y agoThis is a glorious absurdity. I'm seriously wildly impressed. Excellent work!
- omeid2 8y agoI am not too sure about this. The only thing that makes bash tolerable for me is that it is consistently the same kind of ugly across all the platforms. Still, one has to worry about and take care of programs that they depend on in their bash scripts and make sure that the correct version is installed and so, that is hard enough, I don't think adding new syntax and package management is going to help Bash, only make it more complicated and error-prone.
- muterad_murilax 8y agoWhat programs do they depend on?
- Alir3z4 8y agoEXCELLENT WORK! I love how it took the bash to much higher level. I Bash is something you'll end up using, accepted or not. It's available by default and is the best (only?) thing to connect all the dots together when working on Linux machines, either local or servers. This framework is lovely and indeed something that will make my life much easier. Great job, great job!
- cjohansson 8y agoWow, this project really changed my view of bash. It looks more like a ordinary programming language when used in this framework
- ElijahLynn 8y agoI didn't easily see this in the readme.md but it is in the project description. Nice syntax highlighted example here >>> https://invent.life/project/bash-infinity-framework https://invent.life/project/bash-infinity-framework
- kabes 8y agoNice work. Although it seems everytime I need to use bash (actually quite regulary ) I forgot everything about it and need to look up all the basics again. Maybe I don't try hard enough, or maybe its inventor had a totally different logic then I do.
- mar77i 8y agoBash was invented many and many times over, it even says so, being the "Bourne Again Shell". So what you have here is a classic unix sh with extra bells and whistles and some workarounds to shoehorn it onto mordern environments that allow newlines and spaces in file names. For example, it reinvents the [ ... ]/test builtin as [[ ... ]] which bypasses some shell behaviors which can be surprising at times. http://mywiki.wooledge.org/BashFAQ/031 http://mywiki.wooledge.org/BashFAQ/031
- tomc1985 8y agoThe thought of a Bash framework scares me. Next thing you know someone will write React in it... Just freakin learn perl or python! Do not let this beast grow any larger.
- Annatar 8y agoBoth Perl and Python are way more complicated than shell programming, and in all my decades of doing so on the command line, I’ve yet to find a problem which a full blown shell + AWK couldn’t solve. And that combination is still simpler to program in than Python or Perl. Had you grown up on a real UNIX, you’d have never written what you wrote.
- kamaal 8y agoPerl is far more than anything you can ever do in Bash, even the basic things. Then there is also the famous Tom Christiansen Essay on C-shell: https://www-uxsup.csx.cam.ac.uk/misc/csh.html https://www-uxsup.csx.cam.ac.uk/misc/csh.html You can even do Lispy things in Perl. You can do functional stuff: https://hop.perl.plover.com/ https://hop.perl.plover.com/ You can do unicode regexes in Perl: https://perldoc.perl.org/perlunicode.html https://perldoc.perl.org/perlunicode.html You can do large file processing in Perl: https://www.perlmonks.org/?node_id=344087 https://www.perlmonks.org/?node_id=344087 , https://www.perlmonks.org/?node_id=1118102 https://www.perlmonks.org/?node_id=1118102 Perl's file and string manipulation capabilities has no match. If you use awk you have to think in the line paradigm. Perl gives you not just that but a lot more. Perl regexes are by far the strongest of their kinds programming language out there(first class entities). In fact the whole reason why Larry Wall invented Perl is at some point in time you max out what you can do with things like awk and sed.
- Annatar 8y agoI spent 3.5 years debugging and maintaining Perl code. For a living. I have formal education in programming applications in Perl. And I stand by what I wrote about shell + AWK, especially AWK, any day of the week. By the by, I can do unlimited number of things in a shell program, things no other programming language can do, because I can call any other program from it. Apart from assembler, shell is the second most powerful tool because of that characteristic.
- artellectual 8y agoActually bash is extremely powerful. If you do serious ops work or any kind learning bash goes a very long way. I work a lot with bash and this lib just looks very exciting.
- ndesaulniers 8y agoThis is how it starts; once someone figured out php could do more than just #include html fragments, Facebook built an empire with it. Frankly, I'm amazed Bash can do any of this. I'm happy to use a fullscreen terminal all day, and come up with too-clever unix pipelines, but damn do I hate writing anything in Bash, especially when it comes to control flow.
- johnramsden 8y agoPretty amazing what can be done with bash, and it looks very impressive. I can't believe all the features that were able to be put together to make using the library essentially give bash all the features of a full-featured language. However, at the same time I kind of wonder what the use case would be for this. With all the extra syntax it would basically be equivalent to learning a new programming language, at which point it just seems to make more sense to use languages that have these features baked in. While it looks like a really cool project, I could never see myself using it, as usually when I want to use a shell scripting language I want full portability, and end up writing in sh. When I want to write something more advanced I use real programming language.
- brobdingnagians 8y agoThe only use case I can think of is an extremely constrained environment where bash is the only way of interfacing with it. I tried making a really basic router do some more complicated processing once because I couldn't figure out how to get any other programming environment on it; but later realized it was worth just buying better routers that could be modified... or figuring out how to anyways.
- oblio 8y agoOr BOFHs (http://bofh.bjash.com/ http://bofh.bjash.com/) in banks and other "secure" environments.
- shawn 8y agoNo way. Having to program a router in bash seems fun! Send me your old router!
- nisa 8y agocheckout OpenWrt, you have a posix compliant ash shell from busybox and lot's of shellmagic in the base. You can parse json from bash and interact with the router via an system-bus where you can write plugins in posix-sh that can be called via json-rpc from the browser. https://openwrt.org/docs/guide-developer/ubus https://openwrt.org/docs/guide-developer/ubus - example script: https://wiki.openwrt.org/doc/techref/rpcd https://wiki.openwrt.org/doc/techref/rpcd
- jwilk 8y agoTo be a "standard library", it would have to be shipped with bash itself. It is not.
- stephenr 8y agoBash specifically as Bash isn't a great target runtime for cross-platform/distro scripts. If a program is simple enough (or the programmer determined enough) to write it in Bash, POSIX shell is a better option, as it's well defined, and well documented what does what, and how. Relying on Bash specifically makes things much more complicated for not much benefit.
- crehn 8y agoCool stuff, very impressed! Bash is nice since it's available on many systems and is a slightly better superset of sh. However Bash is a large, ugly beast. There are a million edge cases, inconsistencies, obscure options, counter-intuitive intricacies and minute differences between versions and other shells. There's already a ridiculous amount of completely unnecessary complexity to it. I wouldn't want to increase that surface any further. In practice, I try to keep stuff minimal, transparent and close to defaults. Usually that means -x and POSIX compliancy when possible.
- jacobush 8y agoNext up: a package manager and virtual environment.
- erikb 8y agoAnd a JIT-compiler + VM so it can be used on all environments.
- jwilk 8y agohttps://en.wikipedia.org/wiki/Poe%27s_law https://en.wikipedia.org/wiki/Poe%27s_law
- erikb 8y agoI would argue, though, that having some people actually taking it seriously and starting an implementation of that is awesome, part of the joke, and certainly sometimes even the source of some really cool stuff.
- jacobush 8y agoWell, with Emscripten, how hard can it be to get this running on Node? And access the DOM on the browser?
- twic 8y agoHmm. It probably wouldn't be too hard to build a Truffle runtime for bash ...
- jazzyjackson 8y agobrb spending the next month learning bash infinity (Thanks!)
- Annatar 8y agoWhy are people trying to shove everything into frameworks? Any time you use a framework, you have to play by someone else’s rules, limited by that person’s imagination, experience and insight. If you need something that the framework doesn’t provide, well tough noogies, you have to write it yourself! Might as well write it myself anyway with only the parts I need, keeping it lean and mean (sorry but after so many decades of dissappointments, I don’t trust other people to keep it lean and mean for me). Looking at the modules, this is not how an experienced shell programmer would write code; functional — yes; object oriented — never. Part of the reason those of us who write in the shell do so is to escape the horror of meaningless, kilometers long stack traces and unhandled exceptions, allowing us to keep our code small and fast. And bash, couldn’t the author have picked up ksh93 and built upon a powerful, POSIX-compliant programming language? Why aren’t we as an industry striving to be better, instead of propagating de facto fashion trends?
- blumomo 8y agoWhat is the value for an OO bash language except that people who are familiar with bash can now do OO? Or asked differently, why should I prefer Bash Infinity over a CLI written in any existing OO language, let's say Python, which comes which a much bigger library and is already heavily tested?
- bloopernova 8y agoThis is amazing, thank you to the author for creating this wonder! I can think of maybe half a dozen examples in the past few years where this would have been useful. Not all IT stuff is kubernetes or plain containers, so a well-defined bash-based language is something I can see certain shops embracing. Great work!
- muterad_murilax 8y agoIf only such a thing existed for Windows Batch.
- mxuribe 8y agoThere's git for windows [https://gitforwindows.org/ https://gitforwindows.org/] that comes bundled with git bash...While i have not done complex things in git bash, so far it feels like good ol' bash...but on windows. I wonder if this bash infinity could run in git bash...?
- y4mi 8y agothats just cygwin without its dependency manager...
- wenc 8y agoBatch is a much more limited language than bash. Powershell on the other hand is a full blown scripting language and you can do some impressive things with it. Also, on Windows 10, you can run bash directly through Windows Subsytem for Linux. It gives you a full native Ubuntu environment through a binary compatibility layer (so it runs at near native speeds, non virtualized)
- swsieber 8y agoThis looks cool. It looks like it wouldn't be too hard to write a preprocessor to online the includes (to get down to a single file)
- ejanus 8y agoI am learning Bash via exercism.io and I am enjoying. I didn't know about Bash unit test(bats) until recently. Bash Infinity would help me to learn more... My shout out to the creator .
- ape4 8y agoIn the system System V init days most of the init scripts included (via the dot command) the same standard files.
- Sir_Cmpwn 8y agoIf POSIX shell isn't good enough, you should be using a proper programming language. Encouraging this sort of thing is harmful.
- athorax 8y agoCould you clarify? Unless the systems you are using require POSIX compatibility, why limit yourself? I would agree that using a proper programming language for anything more than fairly basic scripts would be a better option, but I don't necessarily see the harm.
- Sir_Cmpwn 8y agoWell, for one, limiting yourslef is a good exercise in restraint. POSIX shell is simpler than the approach shown here. Using a simpler approach keeps your code more readable and understandable, and using POSIX shell as a baseline means a wide variety of people can understand what your code is trying to accomplish. And you never know, you may someday find out that you want to move to an OS which doesn't support bash, or you start to distribute your software and the complaints roll in from the BSD users trying to port it to their OS, or bash makes some backwards-incompatible changes to some arcane behaviors this tool relies on, and since bash isn't standardized you didn't know until it was too late. I wrote a blog post about this, if you want to read more: https://drewdevault.com/2018/02/05/Introduction-to-POSIX-shell.html https://drewdevault.com/2018/02/05/Introduction-to-POSIX-she...
- _jal 8y agoAgree that accepting the POSIX limitations is healthy if doing so works for the project; disagree with the prescriptive tone. There are lots of things people "should" do, and lots of reasons why they don't; sometimes, they're good ones. So how's this for a "should"? Prescriptive advisors should be very cognizant of the dangers caused by people following such advice without understanding why they are doing so. (Hint: the people who need such advice usually don't understand it.) Additionally, such advisors should accept responsibility when those they give advice to do really weird things while trying to follow it.
- mrybczyn 8y agoAs a long time bash user (and abuser), I will just point you to this document, which distills a lot of wisdom: https://google.github.io/styleguide/shell.xml https://google.github.io/styleguide/shell.xml "If you are writing a script that is more than 100 lines long, you should probably be writing it in something else"
- Cthulhu_ 8y agoThe (possible) problem is that by writing it in something else you're adding a dependency on either a runtime (python, ruby, js, etc) or on a compiler pipeline (c, go, etc), so I can understand an aversion to switch to one of those.
- jchw 8y agoBash is already quite a dependency in itself. It's nowhere near as universal as a plain Bourne-compatible shell, and some systems come with fairly old versions of Bash that are unable to cope with some of the more complicated code. If folks are being honest with themselves, they will find it's significantly more sane to rely on a Python interpreter being available than writing Bash scripts. Go binaries have less dependencies than any Bash script, if runtime dependencies are an issue.
- Carpetsmoker 8y agoAdding to this, it's not just bash you have to worry about: also grep, wc, head, cut, and all other external utilities you're calling. There are actually quite a few incompatibilities between different implementations and versions of many of those utilities. Even if you try your best to restrict to the POSIX standard it's quite easy to "accidentally" use an extension, leading to breakage when someone runs it on Linux distro $foo or macOS. Dependencies is a big problem in shell scripts, much more so than most other environments.
- e40 8y agoPerhaps the "should" is soft, but I definitely disagree. There are lots of tasks where BASH is the best tool and more than 100 lines is needed. I have build scripts of complex systems that are >1000 lines. They are easy to understand and maintain and I cannot image doing it in another language.
- deleted 8y ago[deleted]
- cranjice 8y agoThis is an impressive piece of work. However my use case for bash is simple, concise and portable scripts. I don't look forward to encountering (read trying to fix) this in production.
- garettmd 8y agoKeyword for me is portable. The reason I (and I assume most people) use bash is that it's ubiquitous. This framework wouldn't be. Not that it's not impressive and looks fun to try out. But I can't see a lot of use for it in practical terms.
- hyperpape 8y agoFor everyone who's saying "if you need to write a real program, don't use Bash", you're not really addressing the issue. This is clearly an attempt to make a real language out of what you have in Bash. Repeating platitudes about real languages doesn't help. The question is, how well does this framework achieve that? That said...I have my doubts: https://github.com/niieani/bash-oo-framework/issues/17 https://github.com/niieani/bash-oo-framework/issues/17
- Carpetsmoker 8y agoThey are not "platitudes" though, but real-world practical concerns. To give a specific example, even with these extensions you won't be able to handle NULL bytes in your shell script. So if you ever want to store, say, a PNG image in a variable you're screwed. This can be a real problem. I once wrote a shell script to deal with some email data, which worked brilliant right up to the point we had to deal with emails which contained attachments that aren't base64-encoded (an external provider sent it to us that way), at which point it all came crashing down. It took me ages to discover why emails were being mangled and had to rewrite the entire stuff in Python. It was only used in our development environment and not production, so no permanent damage. But still a waste of my time. There are many other cases where you may want to deal with binary data.
- hyperpape 8y agoWhat you just said is a great observation, but it's not what I was criticizing. I was criticizing people who say "Bash is bad, so I hate this new thing." But since this is a project to build something good on top of Bash, that doesn't really address the issue. What you're (very helpfully) pointing out is that is a case where it's just a bandaid, and Bash's flaws shine through. I suspect there will be more. But other comments are just saying "Bash bad", and those are irrelevant.
- navait 8y agoAre there similar frameworks for ZSH?
- kureikain 8y agoThis is so great. After 5 years of SRE career, I love Bash so much. Bash to me is about glue tools together to do something. I think JSON is what make me struggle with Bash the most. JQ solves it to some certain extent but still a PITA. CI, HealthCheck, Utility scripts(especially about extract data from log) are all valid use case for this.
- Teknoman117 8y agoMakes me think of bash on balls, a web platform written in bash - https://github.com/jneen/balls https://github.com/jneen/balls
- cjhanks 8y agoIf you write a working program in BASH, it will probably work until the day you die. That's why I use BASH for any script I want to be able to forget about. Even long scripts, I have written multi thousand line programs in BASH separated into different modules. Some of this could be helpful, but the non standard syntax kind of defeats the purpose.