[ale] [EXTERNAL] Re: Bash Scripts: When to break them into files

Allen Beddingfield allen at ua.edu
Tue Apr 27 11:42:22 EDT 2021


I think it depends on your mindset and expectation.  When I write a script, I assume I will never look at it again.  So, I sit down and hammer it out in one go with sparse/no comments, and no thought to readability.  If I have to revisit it after it is no longer fresh on my mind, I just start from scratch.  I've got a collection of blobs of script that I reuse and will paste in (generating password, sed/awk stuff that I have found useful for repeated use, for example), but for the most part, if I haven't looked at it recently, I just nuke and start over.  My little blobs and snippets of code are persistent, but my main scripts are disposable spaghetti code.
Having said this, I'm not a programmer.  I'm just a sysadmin who uses scripts for managing and automatic repetitive tasks..  I also sort of still use the same mentality and bad habits I developed when self-learning BASIC in the 80s/90s!
Allen B.


--
Allen Beddingfield
Systems Engineer
Office of Information Technology
The University of Alabama
Office 205-348-2251
allen at ua.edu


________________________________________
From: Ale <ale-bounces at ale.org> on behalf of Steve Litt via Ale <ale at ale.org>
Sent: Tuesday, April 27, 2021 10:29 AM
To: ale at ale.org
Cc: Steve Litt
Subject: [EXTERNAL] Re: [ale] Bash Scripts: When to break them into files



I agree wholeheartedly. Because of their quirky syntax, shellscripts
become unwieldy at about 200 lines of code. I'll often do the prototype
in /bin/sh, and then if it starts getting unwieldy, I'll take the
knowledge gained from the shellscript and write one or more Python
programs.

As far as overhead, the minute a process runs a loop over a few hundred
iterations, shellscripts lose any performance advantage they might have
had. Even Python, which is a slow load and pretty slow run, saves tons
of time over a shellscript when such loops are involved.




More information about the Ale mailing list