Live data from Hacker News

Shell-ish scripting in Go with ease

github.com

61–68 of 68 posts

Re: Shell-ish scripting in Go with ease

#61
post #54
post #28

Earlier quoted context omitted.

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.

If a static binary's --help doesn't tell me where the repository lives then I hope the author steps on a lego.

It is no help to you or your team if they step on the Lego, though.

Re: Shell-ish scripting in Go with ease

#62
post #22

Earlier quoted context omitted.

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

I mean, no one really remembers all the flags. They remember a few common ones, due to using them over and over again. If you are making a genuine effort to avoid the shell, you won't ever learn these basic flags -- you are holding yourself back. It is like a person complaining about using the stairs -- "On the rare occasion when I _do_ take the stairs, it is excruciating..." -- the problem is not necessarily with th…

I totally agree. My counterpoint is that this tool is the equivalent of portable stair lift. Yes, it may hinder me from developing the ability to walk up the stairs, but I'm fine with that. The only thing that matters is that I get up the stairs.

Re: Shell-ish scripting in Go with ease

#63

Earlier quoted context omitted.

D 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 [2] Why I use the D programming language for scripting (2021) (50 comments): https://news.ycombinator.com/item?id=36928485 [3…

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

That'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

[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

Re: Shell-ish scripting in Go with ease

#64

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…

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

Does shell scripting really need to go hand in hand with the language flexibility ?

Re: Shell-ish scripting in Go with ease

#65
post #54
post #28

Earlier quoted context omitted.

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.

If a static binary's --help doesn't tell me where the repository lives then I hope the author steps on a lego.

I mean this entirely depends on how things are done where you work. I wouldn't think the back-reference is necessary if all projects have their own repo in some central location (and it's trivial to match the binary's name to a repo).

Re: Shell-ish scripting in Go with ease

#66
post #28

Earlier quoted context omitted.

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.

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

While I see your point, writing a Posix compatible shell script is not trivial. Little errors creep in that "work on my machine" because /bin/sh is a symlink to /bin/bash, but break the script when someone runs it on macOS.

In my experience, you get a lot of cross-platform compatibility when writing Go for zero effort.

Re: Shell-ish scripting in Go with ease

#67
Plenty of languages have a framework to assist with shell/Bash scripting. Nothing wrong with that.

If you look at the Python build-in API, it's pretty terrible. In all fairness, Python strives to work equally well on Windows, Linux, and some other things. Good luck with that.

I prefer doing systems scripting in Python over Bash. But writing converting a Bash script to Python without "Pythonizing" it is a bad time.

Re: Shell-ish scripting in Go with ease

#68

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…

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

Post reply on HN