Tag command-line

 Reply

 Bookmark

Anybody can write good bash (with a little effort)

I used to write a lot of shell scripts before realising that what I was trying to do was treat shell scripting as a "full" scripting language (I won't define here what I mean by "full").

Its not - reach for a higher level scripting language like Ruby or Python when things are getting more complicated, and allow shell scripts to glue things together, or be for quick tasks maybe a few lines long.

When you do write them, this advice is great but it's definitely worth gaining understanding of when you should and shouldn't use them.

Recommended read: Anybody can write good bash (with a little effort) https://blog.yossarian.net/2020/01/23/Anybody-can-write-good-bash-with-a-little-effort

 Bookmark

Safely Creating And Using Temporary Files

This is a great resource to highlight the difficulty of creating temporary files safely - something I've tried to share before but without these great examples.

Its especially bad if using a shared CI/CD server and putting downloaded files into /tmp as you don't know whether it'll be clobbered / stolen by others on the instance

Recommended read: Safely Creating And Using Temporary Files https://www.netmeister.org/blog/mktemp.html

 Bookmark

Use the Unofficial Bash Strict Mode (Unless You Looove Debugging)

This is a great article about how to be safer when writing shell scripts. I am a huge proponent of not using them where possible, and instead moving them to another scripting language (Ruby, Python, Node) which you can test, and use a shared standard library.

Recommended read: Use the Unofficial Bash Strict Mode (Unless You Looove Debugging) http://redsymbol.net/articles/unofficial-bash-strict-mode/

 Bookmark

Learn a little jq, awk and sed

This is a great post - I thoroughly recommend learning how to use common commandline tools such as awk, grep, sed, but also adopting a scripting language for more complicated stuff. I don't mean Bash, or another shell scripting language, but something like Node, Python or Ruby, as it'll give you the opportunity for a greater standard library, as well as tonnes of packages built by others.

Recommended read: Learn a little jq, awk and sed https://letterstoanewdeveloper.com/2019/07/29/learn-a-little-jq-awk-and-sed/

 Bookmark

https://www.vidarholen.net/contents/blog/?p=746

In every programming language, there is a linting tool that can help pick up on some common style issues. ShellCheck isn't one of those - it's so much more!

I've been using it for many years now, and since it came into my life it's honestly changed the way I use shell scripts. There have been so many pitfalls that I've avoided falling into since learning about them (and adding ShellCheck to my Vim linting setup.

This is a great read from Vidar, the ShellCheck author, about a case where it could've caught issues that caused the deletion of a production database!

Recommended read: https://www.vidarholen.net/contents/blog/?p=746 https://www.vidarholen.net/contents/blog/?p=746