<div dir="auto">I set out to solve the same (or similar) use-case some time ago.<div dir="auto"><br></div><div dir="auto"><a href="https://gitlab.com/taikedz/bash-builder">https://gitlab.com/taikedz/bash-builder</a></div><div dir="auto"><a href="https://gitlab.com/taikedz/bash-libs">https://gitlab.com/taikedz/bash-libs</a></div><div dir="auto"><br></div><div dir="auto">I implemented the above micro build suite all in bash. I like to think I know more tricks than the average bash scripter, and that my scripting is much cleaner and more organised</div><div dir="auto"><br></div><div dir="auto"><a href="https://dev.to/taikedz/your-bash-scripts-are-rubbish-use-another-language-5dh7">https://dev.to/taikedz/your-bash-scripts-are-rubbish-use-another-language-5dh7</a></div><div dir="auto"><br></div><div dir="auto">Then again, that may simply be heady, megalomaniac self-delusion.</div><div dir="auto"><br></div><div dir="auto">Use linked resources at your own risk ;-)</div><div dir="auto"><br></div><div dir="auto">-- tk<br><br><div data-smartmail="gmail_signature" dir="auto">// Sent from a mobile device. Typos and brevity may transpire.</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 3 Jan 2022, 13:35 Keith Wyse, <<a href="mailto:kwyse3436@gmail.com">kwyse3436@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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" target="_blank" rel="noreferrer">https://drive.google.com/file/d/1H6jc5lYwLxmRaDU7FGNHm9dDJXpYS-78/view?usp=sharing</a></div>
-- <br>
EdLUG mailing list<br>
<a href="mailto:EdLUG@mailman.lug.org.uk" target="_blank" rel="noreferrer">EdLUG@mailman.lug.org.uk</a><br>
<a href="https://lists.edlug.org.uk/mailman/listinfo/edlug" rel="noreferrer noreferrer" target="_blank">https://lists.edlug.org.uk/mailman/listinfo/edlug</a><br>
</blockquote></div>