Live data from Hacker News

Shell-ish scripting in Go with ease

github.com

21–30 of 68 posts

Re: Shell-ish scripting in Go with ease

#22

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…

>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.

Re: Shell-ish scripting in Go with ease

#23

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…

[deleted]

Re: Shell-ish scripting in Go with ease

#24
post #19
post #16

Earlier quoted context omitted.

Huh, people are extracting whole bunch of value in Python at expense of society . Should I blame Python or its contributor for it?

I fundamentally disagree with the assertion that Python operates at the expense of society. Google is an exploitative monopoly. There’s been plenty of ink spilled on the subject to the point that I feel no obligation to repeat it. While it’s true that GVR is currently employed by Microsoft, the ecosystem of Python is far more anarchic and decentralized.

I think he was probably making a comment about Python in regards to PyTorch and AI's energy usage.

i.e. Whether a language exists "at the expense of society" probably depends less on who makes the language, and more on what you do with it.

Re: Shell-ish scripting in Go with ease

#25
post #10

I just rewrote a tangled 500 line shell script in go. It was my first time writing a golang project at work, so I'm sure it could have been better. But writing it the naive way, with all the required golang error handling, it ended up taking about 10x more lines of code in golang than the original bash script. It does have a dramatically better UX (largely thanks to spf13's cobra and viper), and is way faster than th…

One neat thing about Go that makes it superior to a shell script is that it compiles a statically-linked binary. One self-contained file! Or N if you support N platforms. Did I mention that cross-compilation is trivial?

Re: Shell-ish scripting in Go with ease

#26
post #10

I just rewrote a tangled 500 line shell script in go. It was my first time writing a golang project at work, so I'm sure it could have been better. But writing it the naive way, with all the required golang error handling, it ended up taking about 10x more lines of code in golang than the original bash script. It does have a dramatically better UX (largely thanks to spf13's cobra and viper), and is way faster than th…

This always seemed like the sweet spot for Perl.

It is. Very much so.

Re: Shell-ish scripting in Go with ease

#28
post #10

I just rewrote a tangled 500 line shell script in go. It was my first time writing a golang project at work, so I'm sure it could have been better. But writing it the naive way, with all the required golang error handling, it ended up taking about 10x more lines of code in golang than the original bash script. It does have a dramatically better UX (largely thanks to spf13's cobra and viper), and is way faster than th…

One neat thing about Go that makes it superior to a shell script is that it compiles a statically-linked binary. One self-contained file! Or N if you support N platforms. Did I mention that cross-compilation is trivial?

As someone who once inherited a static binary (without debug symbols, gotta save those few bytes) that should have been a shellscript: Please don't. If your logic reasonably fits into a shell script, then put it there.

Posix shell-compatible scripts will also likely work on all platforms where you go program would've been run.

Re: Shell-ish scripting in Go with ease

#29
post #22

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…

>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 occ…

>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.

Re: Shell-ish scripting in Go with ease

#30

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…

Good 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/

Post reply on HN