Build your program step by step using Shell Scripting - Part 7

Welcome once again to the next lesson of your Course (Tutorial) en línea "Build your program step by step using Shell Scripting." Until the previous lesson we have walked on how to create the following modules of a program based on Shell Scripting using Bash Shell as execution interpreter:

Shell scripting

In this new edition, the seventh (7), we will cover the study of the following module:

CODING LANGUAGE CONFIGURATION MODULE

This module will allow you set up an environment cleansed en UTF-8 in the GNU Operating System runtime environment /Linux, allowing you to indicate to the program the language in which you want it to operate.

This since many times they occur problems with handling characters not ASCII in our programs, preventing us many times from a correct visualization of the messages shown or entered on the screen or extracted (read) by the same program.

Hence, pera work efficiently With the data of text, the environment has to be configured correctly, which its alot easier to debug a problem that has coding problems Yes you can trust your terminal to display correctly vision UTF-8. And this module helps us with that end.

Its content would be the following:


################################################################################
# INICIO DEL MODULO DE CONFIGURACIÓN DEL LENGUAJE DE CODIFICACIÓN DEL LPI-SB
################################################################################

read -p "Introduzca el lenguaje de Codificación de Caracteres de su Sistema Operativo (1 = es_VE / 2 = es_ES / 3 = en_EN): " T_LANG

if [ "$T_LANG" = "1" ]; then
   
   SET_LANG=es_VE

   echo -e '\a'

   echo ""
   echo ""
   echo "#--------------------------------------------------------------#"
   echo "# LA CODIFICACIÓN POR USTED INDICADA FUE: $SET_LANG             "
   echo "#--------------------------------------------------------------#"
   echo ""
   echo ""

   sleep 3
   clear

   elif [ "$T_LANG" = "2" ]; then
    
    SET_LANG=es_ES

   echo -e '\a'

   echo ""
   echo ""
   echo "#--------------------------------------------------------------#"
   echo "# LA CODIFICACIÓN POR USTED INDICADA FUE: $SET_LANG             "
   echo "#--------------------------------------------------------------#"
   echo ""
   echo ""

   sleep 3
   clear

   elif [ "$T_LANG" = "3" ]; then
     
     SET_LANG=en_US

   echo -e '\a'

   echo ""
   echo ""
   echo "#--------------------------------------------------------------#"
   echo "# LA ARQUITECTURA POR USTED INDICADA FUE: $SET_LANG             "
   echo "#--------------------------------------------------------------#"
   echo ""
   echo ""

   sleep 3
   clear

else

   SET_LANG=es_VE

   echo -e '\a'

   echo ""
   echo ""
   echo "#--------------------------------------------------------------#"
   echo "# LA ARQUITECTURA PREDETERMINADA CONFIGURADA FUE: $SET_LANG     "
   echo "#--------------------------------------------------------------#"
   echo ""
   echo ""

   sleep 3
   clear

fi

export LC_ALL=$SET_LANG.UTF-8
export LANG=$SET_LANG.UTF-8
export LANGUAGE=$SET_LANG.UTF-8

locale

sleep 3
clear

read -p "SI DESEA CANCELAR PRESIONE CUALQUIERA DE LOS SIGUIENTES CARACTERES: "s" "S" "y" "Y". DE LO CONTRARIO PRESIONE CUALQUIER OTRA TECLA! : " op

if [[ $op == "y" || $op == "Y" || $op == "s" || $op == "S" ]];

 then

   sleep 3 ; clear ; exit 0

 else

   sleep 3 ; clear ; read -p "EL SCRIPT LPI-SB PROCEDERA HA CONTINUAR, PRESIONE CUALQUIER TECLA PARA CONTINUAR..." && sleep 3 ; clear

fi

################################################################################
# FINAL DEL MODULO DE CONFIGURACIÓN DEL LENGUAJE DE CODIFICACIÓN DEL LPI-SB
################################################################################

As we can understand when reading the code of said module, the same:

  • It asks us with the following message «Enter the Character Encoding language of your Operating System (1 = es_VE / 2 = es_ES / 3 = en_EN):«, indicate to the program the option (the language) in which we want to set the language for Coding language.
  • Then depending on the user's selection, the program shows him a message on the screen that says "THE CODING BY YOU INDICATED WAS: + your_selection". In case of selecting something other than 1, 2 or 3, the program by default configures the UTF-8 environment under the Spanish_Venezolano (es_VE) language.

It does all of this by using the command commands:

export LC_ALL = $ SET_LANG.UTF-8
export LANG = $ SET_LANG.UTF-8
export LANGUAGE = $ SET_LANG.UTF-8

And it shows the result on the screen, by executing the command:

local

Ending with the last warning message to the user that says:

IF YOU WANT TO CANCEL THE PROCESS UNTIL NOW, PRESS ANY OF THE FOLLOWING CHARACTERS: “s” “S” “and” “Y”. OTHERWISE, PRESS ANY OTHER KEY TO CONTINUE, REMEMBER THAT WORKING WITH THE INCORRECT ARCHITECTURE MAY BRING SERIOUS DISADVANTAGES TO THE LPI-SB TO WORK OPTIMALLY!

If the user presses some of the correct characters, the program closes and otherwise it issues the following message and continues its operation:

THE LPI-SB SCRIPT WILL PROCEED TO CONTINUE, PRESS ANY KEY TO CONTINUE ...

=============

RECOMMENDED READING:

GNU, LINUX, GNU / LINUX, FREE SOFTWARE AND OPEN SOURCE!

ALL TOGETHER OR SEPARATELY?

  • What is GNU?
    GNU means GNU is Not Unothing, and refers to World Free Software Project, started in January 1984 by Richard M Stallman, known as GNU project. GNU expressly refers to a Free Software Operating System. The development of the GNU PHILOSOPHY has allowed a computer (computer) to be used without software that tramples the freedom, security and privacy of its users. In summary, GNU covers the Unix-like Operating Systems, that is, it is a grouping of many software: programs, applications, libraries, development tools and even games. Many of the GNU programs are published under the auspices of GNU project and we call them GNU packages.

For more information on GNU you can start with here

  • What is Linux?
    Linux as a concept it is in a very broad sense a reference to a type of Operating system. However, strictly and specifically, Linux refers to a Kernel Type. There is one very used in Operating Systems based on the GNU PHILOSOPHY. The kernel of a Operating system, refers to its kernel, that is, the element (module) that is responsible for managing memory resources, allowing manipulation of file systems, managing network resources, and much more. In short, e
    l Kernel (Core) it is like the main or vital organ of a OS, since he is in charge of the Software (SW) and Hardware (HW) of your computer (computer) can work together, since managing the memory for all running programs and processes, the processing time that running programs and processes use, and managing peripheral accesses and other elements, is everything to manage a computer in an effective and efficient way.

PFor more information about LINUX you can start with here

  • What is GNU / Linux?
    GNU / Linux It is the whole set of software (applications / programs) that make the Linux Kernel a complete Operating system. GNU it is what makes Linux free and open. ANDs in its entirety a Operating system Unix compatible. Two salient characteristics that distinguish it from the rest of the ecosystem of Operating Systems They are: the first, is that it is free, this means that we do not have to pay any payment for some type of licensing to a software development company for the use of it, and the second, is that the system is accompanied by the source code, that is, since it is distributed under the GNU General Public License, the source code must always be at hand (accessible) and any change or resulting product must have this license.

PFor more information about LINUX you can start with here

  • What is free software?
    In simple words is everyone Software (Application / Program) whose license for use and distribution is called LPG or based on it, which was developed by the GNU project. The GPL license promotes and ensures four (4) fundamental freedoms: the
    Freedom of use, Freedom of learning, Freedom of modification, and Freedom of redistribution. Hence, un program is Free software yes and only yes, users have all these freedoms.

For more information on the Free software you can start with here

  • What is Open Source?
    This concept began to be used in the late 90s, and began as part of a marketing campaign stemming from the movement of the Free software, emphasizing the technical and economic benefits arising from the use and development of the Open Source and Free software, without focusing so much on the ethical arguments that the Free software bring. Of all, almost all the software endorsed by the Open Source Initiative is openly recognized as Free software, by the movement and the Community of Free software, for which almost always both concepts together serve many times to refer to the same software.

For more information on the Open Source and its divergences with Free Software you can start with here and by here

================

So far, I hope you have always liked the Shell Scripting class and the Recommended Reading! Until the next class.


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.