Shell Scripting – Tutorial 05: Bash Shell Scripts – Part 2

Shell Scripting – Tutorial 05: Bash Shell Scripts – Part 2

Shell Scripting – Tutorial 05: Bash Shell Scripts – Part 2

In this present post, we will continue the Tutorial 05 from our tutorial series on Shell scripting. Specifically, we will address a series good practice, to take into account when carrying out the same.

Since, in the previous (Tutorial 04) we address others basic practical points related to these, specifically the how they are generated, how they are executed, and what are the parts that make up a bash shell script.

Shell Scripting – Tutorial 04: Bash Shell Scripts - Part 1

Shell Scripting – Tutorial 04: Bash Shell Scripts – Part 1

And, before starting this post called “Shell Scripting – Tutorial 05”, we recommend exploring the following related contents, at the end of reading this post today:

Shell Scripting – Tutorial 04: Bash Shell Scripts - Part 1
Related article:
Shell Scripting – Tutorial 04: Bash Shell Scripts – Part 1
Shell Scripting - Tutorial 03: All About Bash Shell Scripting
Related article:
Shell Scripting – Tutorial 03: All About Scripts and Shell Scripting

Shell Scripting Tutorial 05

Shell Scripting Tutorial 05

Best good practices to create a Script

Top 10 Best Practices for Shell Scripting

Top 10 Best Practices for Shell Scripting

Among the latests Moravia's compositions 10 most important that we can mention are the following:

  1. Indent the code: A code developed in readable form is very vital for its better understanding. And the necessary indentations will offer a clear view of the elaborate logical structure.
  2. Add separating spaces between sections of code: Separating the code into modules or sections makes any code more readable and easy to understand, no matter how long it is.
  3. Comment the code as much as possible: Adding useful and necessary descriptions to each line or order of command, section of code or function developed, makes it easier to understand what has been programmed.
  4. Create variables with descriptive names of your functions: Assigning variable names that clearly describe and identify the function for which it was created helps to understand its purpose.
  5. Use the syntax VARIABLE=$(comando) for command substitution: Instead of, the old way now deprecated following VARIABLE=`date +%F`.
  6. Use modules or variables for validation of superuser and authorized users, with or without a password: To increase security levels, in the required parts of the code.
  7. Use modules or validation variables of the Operating System (Distro, Version, Architecture): To prevent the use of the files on unsupported computers (or servers).
  8. Use modules or procedures to confirm the execution of critical or batch actions: To minimize mistakes due to improvisation or carelessness.
  9. Include assorted essential modules: Among those that can be mentioned, Welcome and Farewell modules, double execution verification, for a better user experience.
  10. Create user-friendly visual interfaces: Both by, Terminal (CLI) and for the Desktop (GUI) using the commands "dialog", "zenity", "gxmessage", "notify-send" and even the commands "mpg123 y espeak" for sonic alerts and audible notifications with humanized or robotic voice.

Other important

  1. Rationalize Script size with External Functions and/or Modules: If a Script will end up being very large, it is best to split it using functions or split it into smaller Script files, which are called by a main Script.
  2. Invoke, in a clear and evident way, the calls to other Interpreters (programming languages) within the Script: To do this, we must invoke them clearly by lines or modules.
Shell Scripting - Tutorial 02: All About Bash Shell
Related article:
Shell Scripting – Tutorial 02: All About Bash Shell
Shell Scripting - Tutorial 01: The Shell, Bash Shell and Scripts
Related article:
Shell Scripting – Tutorial 01: Terminals, Consoles and Shells

Abstract banner for post

Summary

In short, we hope this Tutorial 05 on «Shell Scripting» on the best good practices when making scripts, and the previous ones, are increasing the knowledge of many, when making the most optimal and functional Script files generated with Bash Shell.

If you liked the content, comment and share it. And remember, visit the beginning of our «site», in addition to the official channel of Telegram for more news, tutorials and Linux updates.


Be the first to comment

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.