Shell scripting libraries
To really take advantage of automating tasks using shell scripts, it's important to organize all common tasks into reusable commands and have them available in the path. To do this, it's a good idea to create a bin
folder inside the home directory for the scripts, and a bin/lib
directory for storing common pieces of code. When working with lots of shell scripts, it's important to reuse large pieces of functionality. This can be achieved by writing library functions for your shell scripts, functions that you can call from multiple places.
Here we will create a library script called util.sh
, which will be sourced in other scripts. By sourcing the script, we get access to functions and variables from inside the library script.
We will start by adding the print_ip
function from a previous script.
Now we will add another function called getarg
, which will be used by other scripts for reading command line arguments and values. We will simply paste it from...