Tag shell

 Bookmark

I've recently been doing similar with some of my utilities, albeit with an informal comparison between Ruby and Go versions, but would agree that for large, production critical scrips, this is a great way to do it

Recommended read: Rewriting Bash scripts in Go using black box testing https://stackoverflow.blog/2022/03/09/rewriting-bash-scripts-in-go-using-black-box-testing/

 Bookmark

I very much recommend learning how to use a more well-structured scripting language than Bash, as languages such as Ruby have a great standard library, a huge ecosystem of other libraries, and are commonly installed across machines - this is a great look at partially replacing shell scripts with Ruby

Recommended read: Enhanced Shell Scripting with Ruby https://www.devdungeon.com/content/enhanced-shell-scripting-ruby

 Bookmark

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

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

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