3 ms·
Why shouldn't it be as easy to write system administration programs in Go as it is in a typical shell? 1. Shell scripting offers infinite functionality. You ca
by 0xbadcafebee 2y ago
Why shouldn't it be as easy to write system administration programs in Go as it is in a typical shell?
1. Shell scripting offers infinite functionality. You can shell script with any program in any language. All it needs to do is take input and produce output. And if the functionality doesn't exist, you can create it on the fly, without having to follow any of the traditional rules of programming.
2. Shell scripting is a combination of a grammar, operators, a few simple functions, and an extremely loose coupling with generic i/o and logic. I don't know Go well, but it probably doesn't support a similar flexibility. (most languages are very proscriptive about how you can use the language, so you usually can't make things as easy as they are in a different, more tailored language/interface/paradigm. this is why we have DSLs)
3. Programmers don't really understand the concept of productivity [outside of programming itself]. A programmer would solve a problem by taking 6 weeks to design a perfect program to do the thing. A Sysadmin would take 5 minutes with a shitty language and a shitty tool and get way more done in less time. And re-writing everything into a Go library would always be slower than shell scripting, because it requires re-implementing what a shell script would just use as-is.
Scripting is duct-taping the wheel rather than reinventing it. If you want to save yourself a whole lot of time and trouble, just use the duct tape.
(also: don't go templates exist? why isn't that used for scripting)
- skydhash 2y agoI believe point 2 is the best. Shell scripts are usually software coordinators. Before even starting you already have a collection of software that already does most of the work. The script is just to speed the execution. As an analogy, it's like serving already cooked dishes you ordered. While a programming language is like having the ingredients, and cooking everything yourself. More versatile, but not that easy. And as you say, the first option is better when everyone's hungry.
- graerg 2y ago>A Sysadmin would take 5 minutes with a shitty language and a shitty tool and get way more done in less time. Most people aren't sysadmins, but occasionally have to do sysadmin-like things. I've been programming with python and go for years. I've never been able to get the "core" command line utilities to really stick in my head. A sysadmin uses them every day, whereas I rarely have to reach for them. On the rare occasion when I _do_ have to reach for them, it is excruciating (what was the flag I need for `find` again?). If it were life or death and I had to debug even the simplest sed/awk command, it would be death for me! But this package makes perfect sense to me and really enables me to write this sort of quick and dirty thing in a language I'm familiar with and can confidently maintain. This isn't for everyone, but there's definitely a population that can get a lot of value out of this.
- wpm 2y ago>what was the flag I need for `find` again This is not on you, `find`'s command line syntax is awful even if you have to use it everyday.
- mbreese 2y agoAnd don’t forget GNU vs BSD version differences…
- sgarland 2y agoThat’s why you install gnu-coreutils. Eliminate the difference.
- oguz-ismail 2y ago> `find`'s command line syntax is awful What's awful about it?
- DaSHacka 2y agoEverything? It, just like tar, don't follow the convention of many other CLI utilities. That alone is why I prefer `fd` or plocate for most tasks I previously used find for.
- oguz-ismail 2y agoNever heard of plocate but I thought fd a step down from find; it's very limited in functionality, colorful output alone can't justify that. > [It doesn't] follow the convention of many other CLI utilities. Because unlike other CLI utilities, find evaluates an expression specified as arguments. Maybe a small DSL like JQ would be better, but how would you embed shell code in it? Meh.
- DaSHacka 2y agoFind has its uses, I use it frequently to correct improper unix file permissions and owners and when I need to execute a command on a list of files. However for the vast majority of queries, I'm only looking for something based on the filename, and that's where having sane regex and standard argument structure (like fd has) is great.
- deleted 2y ago[deleted]
- stonewhite 2y agoGood points. 3rd one reminds me of the Knuth vs McIllroy story about 10+ page pascal vs 6 bash pipes[1] [1]: https://leancrew.com/all-this/2011/12/more-shell-less-egg/ https://leancrew.com/all-this/2011/12/more-shell-less-egg/
- jayd16 2y agoYou can run a shell command from a language you like so they're just as flexible. Go and many other languages have Exec (or equivalent). The major reason shell scripting is nice is because its portable with a copy/paste and HelloWorld.sh doesn't need a compiler or a VM or even any preceding incantation to run. As much as I hate that this is where my hopes are, I do hope that Powershell gets to a point where you can write single C# files and run them.
- teleforce 2y agoD language rdmd wrapper allows to compile-and-execute directly [1]. Together with intuitive function calling facility using Uniform Function Call Syntax or UFCS you can easily has natively compiled scripting environment [2],[3]. [1] Pragmatic D Tutorial: https://qznc.github.io/d-tut/hello.html https://qznc.github.io/d-tut/hello.html [2] Why I use the D programming language for scripting (2021) (50 comments): https://news.ycombinator.com/item?id=36928485 https://news.ycombinator.com/item?id=36928485 [3] Uniform Function Call Syntax: https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax
- Zamiel_Snawley 2y agoYou can write executable “scripts” in C by JIT compiling them with the shebang. Tcc has the `-run` flag for easily doing this with a normal-ish shebang. With a nasty polyglot preamble of C and bash at the top of your file, you can do it with any compiler.
- teleforce 2y agoThat's a good thing but due to D syntax it is very intuitive and pythonic due to the default GC, in addition to the UFCS feature that I've mentioned compared to C with its agrarian syntax. That's the main reason we have C shell scripting in the form of csh with more intuitive syntax for example foreach loop that D has already supported [1]. But if you insist, D now supports and can compile C language that you can perform using rdmd [2]. [1] C shell: https://en.wikipedia.org/wiki/C_shell https://en.wikipedia.org/wiki/C_shell [2] Adding ANSI C11 C compiler to D so it can import and compile C files directly (105 comments): https://news.ycombinator.com/item?id=27102584 https://news.ycombinator.com/item?id=27102584
- lelanthran 2y ago> I don't know Go well, but it probably doesn't support a similar flexibility. I know Go okay-ish, and you can remove the 'probably' from that sentence. Hell, even using Python for shell scripting is a pain in the rear, and that's way more flexible than Go.
- demi56 2y agoDoes shell scripting really need to go hand in hand with the language flexibility ?
- tonymet 2y agoalmost all of the most useful scripting languages are some sort of bridge to native functionality . PHP, awk, Perl , to a lesser degree python. The author is trying to bring the better type checking, concurrency, deterministic syntax and error handling of go to the world of shell scripting. Most scripts end up becoming programs themselves and go beyond their original scope. It would be nice to force better concurrency & error handling early on before the script takes on 5k lines of functionality.