Earlier 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.
Ask HN: How can I get better at bash?
31–40 of 195 posts
Re: Ask HN: How can I get better at bash?
#32Re: Ask HN: How can I get better at bash?
#33Re: Ask HN: How can I get better at bash?
#34I used to lean on python for much of my scripting needs, mainly because the more advanced bash syntax was pretty daunting. Getting better at bash has a trickle-down effect, especially in this container age. ENV var scoping + loops and various var expansion methods really made it click for me. Shelling out to various tasks (and grabbing the results) is effortless via bash scripts. With bash on windows now it's pretty…
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…
Re: Ask HN: How can I get better at bash?
#35I learned to use shell, about 7 years ago, by reading O'Reilly "Classic Shell Scripting". It is well written, and teach you something that you can hardly learn from google. But don't try to remember everything, especially those advanced string manipulation syntax, because one would usually use a scripting language such as ruby for advanced job.
Re: Ask HN: How can I get better at bash?
#36Earlier quoted context omitted.
Then you have the age old problem: what if one of the tasks in your pipeline(s) fails?
set -o pipefail -o errexit Add more options to taste.
Not pipefail as such, but Bash's error handling semantics (or lack there of) is pretty lame.
Re: Ask HN: How can I get better at bash?
#37Re: Ask HN: How can I get better at bash?
#38 set files [glob /etc/*.conf]
foreach f $files {file lstat $f file_info; puts "$f: $file_info(size)"}
/etc/asl.conf: 1051
/etc/autofs.conf: 1935
/etc/dnsextd.conf: 2378
... and so forth ...
Also there is an `exec` command that supports pipes, redirections, and so forth: set result [exec cat /etc/passwd | grep Directory]
The pipe has no special meaning in Tcl, but because of its DSL capabilities you can do things like that. Exec is a DSL basically.Re: Ask HN: How can I get better at bash?
#39Everything will take longer but imho it's the only way to get better.
Re: Ask HN: How can I get better at bash?
#40Figure out a problem and try solving it in bash - bash for beginners guide on tldp site can get you started. You get better as you use it. http://www.tldp.org/LDP/Bash-Beginners-Guide/html/ EDIT : Additional links - Advanced - http://tldp.org/LDP/abs/html/ Bash programming - http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html