Shell Scripting – Tutorial 07: From theory to practice – Part 01

Shell Scripting – Tutorial 07: From theory to practice – Part 01

Shell Scripting – Tutorial 07: From theory to practice – Part 01

Continuing, with this Tutorial 07 from our series on Shell scripting, today we will address the first part of a series of practical examples, to take into account to start learn and refine our dominion over Shell Scripting Technique.

In addition, from here, we will be able to use everything known and learned, in the previous tutorials 06 and 05 (Online Resources and Good Practices), without forgetting all the theoretical basis assimilated into the tutorials 04,03, 02 and 01.

Shell Scripting – Tutorial 06: Bash Shell Scripts – Part 3

Shell Scripting – Tutorial 06: Bash Shell Scripts – Part 3

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

Shell Scripting – Tutorial 06: Bash Shell Scripts – Part 3
Related article:
Shell Scripting – Tutorial 06: Bash Shell Scripts – Part 3
Shell Scripting – Tutorial 05: Bash Shell Scripts – Part 2
Related article:
Shell Scripting – Tutorial 05: Bash Shell Scripts – Part 2

Shell Scripting Tutorial 07

Shell Scripting Tutorial 07

Examples of commands to start in the Shell Scripting – Tutorial 07

Knowing predefined values ​​and parameters: Export and Env commands

To begin with, it is important to know that many of the most important and used values ​​or parameters, are already predefined in certain variables of the Operating System, which can be known through the commands "Export"And"Approx", as we can see in the following images:

Export

Export command output - 1

Export command output - 2

Approx

Env Command Output - 1

Env Command Output - 2

Therefore, in a terminal we could execute, for example, the following command orders to read (extract/know) the used desktop environment, depending on the “Export” and “Env” commands:

echo $XDG_SESSION_DESKTOP

echo $DESKTOP_SESSION

And so get the same result by terminal, in my case: XFCE. As shown below:

command orders to read (extract/know) the used desktop environment

Extract Stored Values ​​and Parameters Using Shell Scripting

And then we'll learn extract values ​​and information of various types through executing command orders in a terminal. Starting with some simple ones like today, until reaching more advanced ones, in future tutorials.

While today's are the following:

NE=$(cat /etc/hostname) ; echo $NE
#Nombre del Equipo.

F1=$(date +"%D") ; echo $F1
#Fecha actual del Sistema

F2=$(date +"%d-%b-%y") ; echo $F2
#Fecha actual del Sistema

F3=$(date +"%d-%m-%y") ; echo $F3
#Fecha Numérica actual del Equipo

F4=$(date "+%d-%m-%y_%H-%M-%S") ; echo $F4
#Fecha actual extendida del Sistema

H1=$(date +"%T") ; echo $H1
#Hora actual del Sistema

H2=$(date +"%H-%M") ; echo $H2
#Hora actual del Sistema

H3=$(date +"%H-%M-%S") ; echo $H3
#Fecha actual extendida del Sistema

H4=$(date +"%H") ; echo $H4
#Hora del Sistema

M1=$(date +"%M") ; echo $M1
#Minutos del Equipo

S1=$(date +"%S") ; echo $S1
#Segundos del Sistema

D1=$(date +"%d") ; echo $D1
#Día actual del Equipo

MES1=$(date +"%b") ; echo $MES1
#Mes alfabético actual del Equipo

MES2=$(date +"%m") ; echo $MES2
#Mes numérico actual del Equipo

A1=$(date +"%y") ; echo $A1
#Año (con 2 cifras) actual del Equipo

A2=$(date +"%Y") ; echo $A2
#Año (con 4 cifras) actual del Equipo

When executing them in a terminal this would be the result on the screen:

Screen result of executed command orders

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

Abstract banner for post

In short, we hope this Tutorial 07 on «Shell Scripting» with the Part of a series of useful command orders to begin to learn and understand the potential of this technique, allow them, in the immediate future, a more advanced and practical management their GNU/Linux operating systems. And of course, the power to reach build your own CLI/GUI programs, If necessary.

Just as, personally, I carry out with the construction of a app (package) Debian called LPI-SOA, done 100% with Bash via Shell Scripting, about the future version of me Community Respin based MX Linux called Miracles. And what can they see in me? YouTube channel, in order to know the power (scope) of Shell Scripting.

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. West group, for more information on today's topic or other related ones.


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.