help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simpler question about my script


From: Dave Jennings
Subject: Re: simpler question about my script
Date: Wed, 16 Feb 2022 12:48:13 +1100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0

On 16/2/22 10:38, Alex fxmbsw7 Ratchev wrote:
On Wed, Feb 16, 2022 at 12:17 AM Dennis Williamson <
dennistwilliamson@gmail.com> wrote:

...


On Tue, Feb 15, 2022 at 2:51 PM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
wrote:

. . .

ill try to recode it readable for other ppl then ask again




That will go a long way toward making it easier for you as well. Readable
code is easier to understand and maintain and is self-documenting. Using an
editor with syntax highlighting is helpful when looking for syntax errors
and unbalanced delimiters. Auto indenting and code completion and many
other helpful features are also available.


i failed, i wrote as usual, with some comments, and u see in v3 it looks
unreadable
but i dont care sorry understand its build out of small files to one big
script, .. the tree is few files named by functions and vars

indending as in spaces and tabs i cannot take anymore, i went in 20y+ of
coding only problems with it
and the syntax highlightening i've seen were... broken and not goodly
visible, ...


A few tips (some are specific to shell scripts):


i read some of em, they are not for me, they are for more newbies

Just a quick comment on this, I read Dennis's tips and thought they were great. I'm a 30+ years developer who's worked on a aircraft navigation system that contains 10's of thousands of lines of bash (and a lot of C++).

Not just for newbies.

Organize code into functions and use clear entry and exit points. Don't
intermingle top level code and function definitions.

Use proper nested indentation to make control statement (for, if, while)
bodies stand out. Don't use one-liners in scripts.

Use meaningful names for variables, functions and other elements. Avoid
single-letter names.

When an external program provides a choice of long or short options, use
the long ones (when portability isn't an issue). Long options improve
readability.

Use if-then-elif-else-fi instead of boolean operators.

Never use aliases in scripts. Use functions instead.

Avoid being clever. Clarity is important. Avoid side effects whenever
possible.

Use variables to hold values instead of hard-coding the values where
they're used. This helps document the code and improves maintainability.
Set a variable to the value of a positional parameter (e.g. user_name=$1)
for the same reasons.

Know when and why to bend the rules, but keep it to a minimum.

Some of these tips are intended to draw a distinction between command-line
use where brevity has value and scripting where clarity is a higher
priority.

There are many other good guidelines you can make use of. These are some
basic ones focused on code clarity. Functionality and performance are
beyond the scope of this message.

Comments are welcome.

Dennis

--
Visit serverfault.com to get your system administration questions
answered.


well you meant it well so i comment on your mail, im a bit higher and
stricter level there than the tips

i suggest.. you, make a documentational text with such things and public it
its what im doing ( when im on it ) , i write httpd in bash and host free
fun services on it.. u can too

i mean the tips are not non sense, do something with them



reply via email to

[Prev in Thread] Current Thread [Next in Thread]