Settings

Theme

Ask HN: How does one practice day to day shell scripting

2 points by mindentropy 2 years ago · 4 comments · 1 min read


As a developer my job does not involve day to day shell scripting. It comes up occasionally and due to this I face a problem now where I forget the syntax and will have to look it up again which takes a long time. I want to improve on this and would like to be fluent and for this I need to script on a regular basis.

I would like to know how people of HN keep in touch with scripting on a regular basis as a part of your job and what are the practices that you follow.

dxs 2 years ago

I'd say check out the work of William Shotts at https://linuxcommand.org/ His book, "The Linux Command Line" is free for downloading, and there are lots of references to style guides, good practices, and bash templates in the book.

There is also a shorter, HTML version at the same site: https://linuxcommand.org/lc3_learning_the_shell.php

I'm trying to get a little proficiency in all this, and just yesterday I went through the "Further Reading" sections at the end of each chapter, and captured all the likely URLs for further investigation.

One that looks really good is Dylan Araps' "Pure Bash Bible" ( See https://github.com/dylanaraps/pure-bash-bible ) Confession: I found a PDF copy at Libgen, but don't tell anyone. This and the Shotts book have also been thoroughly discussed on Hacker News in the past. (I.e., search on the two titles and you'll probably get all the opinions that you can stand, plus maybe some more hints.)

Bash is profoundly weird, but if/when you can make it work, it's slick.

dxs 2 years ago

I forgot to mention "shellcheck" at https://www.shellcheck.net/ and the explanation of its error codes at https://www.shellcheck.net/wiki/

This is also referenced by Shotts, and has been discussed on Hacker News -- not to be missed.

fiedzia 2 years ago

Don't. My rule is if it's more then 3 lines or more complex than simple commmand call, it'll be written in Python. It will be easier to read for everyone around and avoid all the shell footguns.

  • mindentropyOP 2 years ago

    I work in embedded and many times I will be dropped to minimal shells where I don't access to interpreters like Python.

    Also whenever I need to do some repetitive file operations writing shell scripts in the command line becomes important.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection