<div dir="ltr">Hi all;<br>I hope your New Year is going well so far.<br>Recently I have been doing some Bash scripting on my Ubuntu 21.04 desktop, and found I was repeating similar commands in different scripts.<br>Though I have been using Bash for quite a while, I'm no expert and am still learning all the time.<br><br>I found the 'source' command which brings in another file as if it were part of the script, and have been using that in a similar way to a library in a programming language.<br>I have built a few of these templates as I call them, and then also combined templates into profiles; a script that only needs a log file can source profile.logfile, a different script which needs to check sudo permissions sources profile.all. Each of these pull in just enough for the actions to be done.<br>Also at the top of each template/profile I have added a commented out section which shows the normal use, so that this can easily be copied to a script being written.<br><br>Then I realised that I have some scripts which call other scripts, and pulling in templates/profiles in the called script may change set variables. To handle that I added an 'if' condition to test if the variable is already set. And at the end I have added another 'if' to test if the script is the top level, only then is the variable unset in the tidy-up.<br><br>Further I have added functions which test if the set variable is correct and I try to have a function 'template.valid' in each template which makes all necessary checks on the variable.<br>Yes this might seem to be unnecessarily pedantic, but it is a learning exercise as well as functional.<br><br>Linked is a small file template.cmndname which simply sets a variable according to what script is being executed. In essence it's only a single line, but the template goes further & checks it is valid. This template is normally set in each script whether or not it is called from another script, as I use this in messages.<br><br>Let me know if the link works okay.<br>Interested in people's comments & suggestions.<br><br>Cheers<br>Keith<br><br><a href="https://drive.google.com/file/d/1H6jc5lYwLxmRaDU7FGNHm9dDJXpYS-78/view?usp=sharing">https://drive.google.com/file/d/1H6jc5lYwLxmRaDU7FGNHm9dDJXpYS-78/view?usp=sharing</a></div>