I'm ok at bash, but I do not default to complicated bash scripts for my needs. I make little reusable tools. For example I have a tool aliased that makes it easy to apply quick ruby code. For example echo "345.44 544.50" | rg "€#{l}: €#{(l.to_f * 3).to_i}" Produces the following output: €345.44: €1036 €544.50: €1633 Based on this code: https://gist.github.com/zachaysan/4a31386f944ed31a3f8a920c85... I find it's much f…
Ask HN: How can I get better at bash?
61–70 of 195 posts
Re: Ask HN: How can I get better at bash?
#62Re: Ask HN: How can I get better at bash?
#63Read Greg's wiki - BashGuide: http://mywiki.wooledge.org/BashGuide
Re: Ask HN: How can I get better at bash?
#64How about you don't? Bash as scripting language is rather mediocre. Anything that is not simple in bash gets hard to read and debug and probably is wrong on some subtle levels. I have a rule of thumb that any shell script that grows beyond a screenful of lines gets redone in a proper scripting language.
Bash as a scripting language is actually pretty amazing. It gives you everything you need to perform some quick-and-dirty tasks with minimal overhead. If you need only work on sequential data, files and processes, it's a perfect match. It's not a full-fledged programming language by any stretch of the imagination (lacking structures more complex than associative arrays), but it's damn good for scripts of all sorts. A…
Re: Ask HN: How can I get better at bash?
#65Earlier quoted context omitted.
OTOH, if you can structure your problem as a composition of pipelines, it can be quite a bit faster in bash than in a "proper" language. You get to choose optimized tools, and they run concurrently. Writing efficient bash code forces you to think about your problem differently. It's a very similar process to thinking functionally; e.g. you don't want to deal with lines of a file one at a time in a loop, you want to d…
Is there a "proper scripting language" somewhere that supports the same first-class access to Unix programs and the same piping | syntax that shells in general do? I would love something like that.
Re: Ask HN: How can I get better at bash?
#66Earlier quoted context omitted.
In both my personal and professional life, I have the opposite conclusion. Bash is only for the simplest scripts and pipelines, and everything else (assuming you're going to use it more than once) gets written in Python or Go. The Bash syntax is not daunting, or if it is that's never been the problem with Bash. The problem is that Bash or shell programming in general gives you a million ways to shoot yourself in the…
> Like iterating over the files in a directory, for example. If you think that's easy in Bash you have either have a funny definition of easy Maybe I'm overlooking something...but why wouldn't this work: for file in $(ls); do { }; done
$ mkdir "hi there"
$ mkdir "how are you"
$ ls -l
total 8
drwxr-xr-x 2 xxxxxxxx xxxx 4096 Jun 26 14:54 hi there
drwxr-xr-x 2 xxxxxxxx xxxx 4096 Jun 26 14:54 how are you
$ for f in $(ls); do echo $f; done
hi
there
how
are
youRe: Ask HN: How can I get better at bash?
#67Re: Ask HN: How can I get better at bash?
#68Re: Ask HN: How can I get better at bash?
#69Vivek (founder) has been writing these tutorials for 17+ years, he knows his stuff.