Live data from Hacker News

Shell-ish scripting in Go with ease

github.com

41–50 of 68 posts

Re: Shell-ish scripting in Go with ease

#41
post #29

Earlier quoted context omitted.

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

> `find`'s command line syntax is awful What's awful about it?

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

Re: Shell-ish scripting in Go with ease

#42

Earlier quoted context omitted.

> `find`'s command line syntax is awful What's awful about it?

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

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

Re: Shell-ish scripting in Go with ease

#44

Earlier quoted context omitted.

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

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

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

Re: Shell-ish scripting in Go with ease

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

500 lines of bash could have been rewritten as 50 lines of dense Perl. Pro: fewer lines of code. Con: even the author would find the Perl script inscrutable after a few weeks.

Re: Shell-ish scripting in Go with ease

#46

Earlier quoted context omitted.

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

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

> for the vast majority of queries, I'm only looking for something based on the filename

I'd manage with find|grep but yes, nothing wrong with wanting something more compact.

> sane regex

For me that's POSIX ERE, I don't know which flavor fd uses.

Re: Shell-ish scripting in Go with ease

#47

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.

Re: Shell-ish scripting in Go with ease

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

Or just make sure the source is available.

Re: Shell-ish scripting in Go with ease

#49
post #29
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…

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

[deleted]

Re: Shell-ish scripting in Go with ease

#50

This site is horrible. Every comment here is trying their hardest to systematically dismantle this library out of existence through the use of nihilistic mind-games about what "shell scripting" "really" "is". All because they don't like a programming language that much.

right?
Post reply on HN