[EdLUG] Bash Scripts

Tai Kedzierski dch.tai at gmail.com
Tue Jan 4 07:53:32 UTC 2022


I set out to solve the same (or similar) use-case some time ago.

https://gitlab.com/taikedz/bash-builder
https://gitlab.com/taikedz/bash-libs

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

https://dev.to/taikedz/your-bash-scripts-are-rubbish-use-another-language-5dh7

Then again, that may simply be heady, megalomaniac self-delusion.

Use linked resources at your own risk ;-)

-- tk

// Sent from a mobile device. Typos and brevity may transpire.

On Mon, 3 Jan 2022, 13:35 Keith Wyse, <kwyse3436 at gmail.com> wrote:

> Hi all;
> I hope your New Year is going well so far.
> Recently I have been doing some Bash scripting on my Ubuntu 21.04 desktop,
> and found I was repeating similar commands in different scripts.
> Though I have been using Bash for quite a while, I'm no expert and am
> still learning all the time.
>
> 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.
> 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.
> 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.
>
> 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.
>
> 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.
> Yes this might seem to be unnecessarily pedantic, but it is a learning
> exercise as well as functional.
>
> 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.
>
> Let me know if the link works okay.
> Interested in people's comments & suggestions.
>
> Cheers
> Keith
>
>
> https://drive.google.com/file/d/1H6jc5lYwLxmRaDU7FGNHm9dDJXpYS-78/view?usp=sharing
> --
> EdLUG mailing list
> EdLUG at mailman.lug.org.uk
> https://lists.edlug.org.uk/mailman/listinfo/edlug
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.edlug.org.uk/pipermail/edlug/attachments/20220104/b95cf700/attachment.htm>


More information about the EdLUG mailing list