29 ms·
I sometimes wonder why bash transpilers aren't more popular? Bash is such a strange language (or maybe just very old with lots of cruft) that it's impossible to
by superasn 6y ago
I sometimes wonder why bash transpilers aren't more popular? Bash is such a strange language (or maybe just very old with lots of cruft) that it's impossible to write anything meaningful without check SO 5 times.
Given i haven't spent a lot of time writing shell script yet but the syntax is just super weird, like I recently learned(1) that when you When you write if [ -e /etc/passwd ]; then .. that bracket is not shell syntax but just a regular command with a funny name.
Is there a recommended bash transpiler like what babel is to Js? So i can write bash scripts using a more coherent language and it spits out .sh files.
(1) https://news.ycombinator.com/item?id=26701079 https://news.ycombinator.com/item?id=26701079
- gspr 6y agoI wouldn't go that far as calling it impossible, but it sure is crufty and quirky seen with modern eyes. My "favorite" (i.e. most terrifying) BASH fact is this: https://unix.stackexchange.com/questions/121013/how-does-linux-deal-with-shell-scripts https://unix.stackexchange.com/questions/121013/how-does-lin...
- codetrotter 6y agoInteresting that the answer to that question names the file as .bash – I do this too, but I didn’t know anyone else did. I do this because my shell scripts use bash specific features, and I want to distinguish them from portable shell scripts that use POSIX shell features only. The latter being the only files that really deserve being named as .sh in my eyes :)
- Hendrikto 6y ago> I recently learned(1) that when you When you write if [ -e /etc/passwd ]; then .. that bracket is not shell syntax but just a regular command with a funny name. That’s how it used to be. Nowadays, most of the time it is a built-in, not it‘s own executable anymore.
- devit 6y agoThat's false, [ is a bash shell builtin (it's also a coreutils program, but the program is not called unless you specify /usr/bin/[ or use a shell that doesn't have it built-in).
- pastage 6y agoNot sure how another standard would make it better. But sure maybe something that used dash as a backend. It does seems like it really would suck to actually use, if my little experience with Javascript eco system is anything to go on. So different perspectives maybe?
- GuB-42 6y agoThat's more or less what Perl is (a more coherent language). Perl may look ugly, but it doesn't have the escaping problems that Unix shells have. And most of the usual shell features (listing files, launching commands, etc...) are built-in. It is also available in almost all Unix systems, maybe even more so than bash.
- nikau 6y ago> It is also available in almost all Unix systems, maybe even more so than bash. That's a bit of a deceitful claim - maybe bash isn't on every UNIX box but /bin/sh sure is along with awk and cut and all the other associated helpers. Even if perl is installed its likely missing all the cpan modules that make it useful which isn't great if the host doesn't have carte blanche access to install whatever it feels like. As a sysadmin/devops person knowing the utilities that are guaranteed to be installed is essential, especially now that docker images trimmed of any fat are trendy for bogus security ideals.
- dolmen 6y agoThe CPAN modules availability can be worked around using App::FatPacker. https://metacpan.org/pod/App::FatPacker https://metacpan.org/pod/App::FatPacker That's what I'm using for github-keygen for maximum portability. https://github.com/dolmen/github-keygen/ https://github.com/dolmen/github-keygen/
- nikau 6y agosure, but then you have the overhead of packaging all that junk up vs a single .sh file.
- hnlmorg 6y ago`if` and iterations were two things that annoyed me about bash enough to write my own $SHELL. It's not a transpiler though so I can't realistically use it for production services. However for quickly hacking stuff together for testing / personal use it's been a life saver due to having the same prototyping speed of bash but without the painful edge cases. Not suggesting it's suitable for everyone though. But it's certainly solved a lot of problems for me. https://github.com/lmorg/murex https://github.com/lmorg/murex