Live data from Hacker News

Ask HN: How can I get better at bash?

news.ycombinator.com

31–40 of 195 posts

Re: Ask HN: How can I get better at bash?

#31
post #22
post #17

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.

Just found out that xon.sh http://xon.sh/tutorial . html does this.

Re: Ask HN: How can I get better at bash?

#32
The shell language itself is pretty simple and featureless. It relies on the system utilities for most things so once you know the basics of how the shell works you should probably focus on learning those rather than bash. Also I find that when it comes to interactive use having good key bindings and some nice aliases makes a lot of difference.

Re: Ask HN: How can I get better at bash?

#34
post #3

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

Fair enough! I'm more in the devops/platform space so worrying about python versions and setting GOPATH is wasted time for my purposes. What I love is the portability with minimal effort.

Re: Ask HN: How can I get better at bash?

#35
Flame war between bash/fish/zsh/powershell is almost meaningless to beginners, because the basic skills are common to all shells. (That said, you will love zsh once you use it)

I 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?

#36
post #29
post #18

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

https://stackoverflow.com/questions/29532904/bash-subshell-e...

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?

#38
The Tcl programming language is what shell scripting should be, basically. It is not just a language with all the features you need, it has explicit Unix shell alike scripting capabilities and strong DSL abilities. An example two-liner:

    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?

#40
post #6

Figure 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

ABSG is always my answer to how to learn shell
Post reply on HN