Today I've watched a presentation by Marcin Stożek called
How to train your BASH and wanted to remember the most interesting points for later.
1. It's best if you follow a style guide
There seems to be only one though
Google Shell Style Guide.
It sets more human-friendly defaults and makes sure you won't miss any errors in your scripts.
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
3. Shellcheck
Turns out there is a tool called
shellcheck that can help you write scripts that you intended to write. Best thing is that it explains what's wrong and gives you suggestions on how you can fix it.
4. You can enable 'debug mode' when running your script
Just pass "-x" to the script eg.
> bash -x ./my_script.sh
No one wants to see weird errors when running the script on a new server so it's best if you avoid using external programs in your scripts.
There is much more in the presentation so take a look at it: https://slides.com/perk/jak-wytresowac-basha#/
Comments
Post a Comment
Comments: