Shell Scripting – Tutorial 10: From theory to practice – Part 04

Shell Scripting – Tutorial 10: From theory to practice – Part 04

Shell Scripting – Tutorial 10: From theory to practice – Part 04

In this Tutorial 10 of our current series on Shell scripting, we will continue with another set of practical examples en forma de command orders, addressed in the Tutorial 07, 08 and 09.

In addition, in tutorials 06 and 05, we address various Online Resources and some Best Practices. While much of the theoretical basis of the scripting language was covered in the tutorials 04 to 01.

Shell Scripting – Tutorial 09: From theory to practice – Part 03

Shell Scripting – Tutorial 09: From theory to practice – Part 03

And, before starting this post called “Shell Scripting – Tutorial 10”, we will recommend you to also explore the following related contents, at the end of reading it:

Shell Scripting – Tutorial 09: From theory to practice – Part 03
Related article:
Shell Scripting – Tutorial 09: From theory to practice – Part 03
Shell Scripting – Tutorial 08: From theory to practice – Part 02
Related article:
Shell Scripting – Tutorial 08: From theory to practice – Part 02

Shell Scripting Tutorial 10

Shell Scripting Tutorial 10

Examples of commands to start in Shell Scripting

Extract values ​​and parameters related to Kernel data and System Memory

Next, our command commands from today, for learn shell scripting

TKERNEL=$(uname -s) ; echo $TKERNEL
Tipo de Kernel del SO detectado.

RKERNEL=$(uname -r) ; echo $RKERNEL
Versión del Kernel del SO detectado.

VKERNEL=$(uname -v | awk '{print $4}') ; echo $VKERNEL
Nombre del Sistema Operativo encontrado.

ARQDISTRO=$(uname -m) ; echo $ARQDISTRO
Arquitectura del Sistema Operativo encontrado.

ADCHECK=$(uname -m) ; if [[ "$ADCHECK" = "x86" ]]; then ADCHECK=32; else ADCHECK=64; fi ; echo $ADCHECK
Convertir el Tipo de Arquitectura de la Distro detectada en forma codificada (32 para x86 y 64 para x86_64)

VBASH=$(bash --version | grep bash | awk '{print $4}' | sed 's/(//' | sed 's/)//' | sed 's/-release//' | sed 's/.$//') ; echo $VBASH
Versión del Bash Shell.

TMEMRAM=$(free -h | sed '1 d' | grep Mem: | awk '{print $2}') ; echo $TMEMRAM
Memoria total del Equipo.

UMEMRAM=$(free -h | sed '1 d' | grep Mem: | awk '{print $3}') ; echo $UMEMRAM
Memoria usada del Equipo.

FMEMRAM=$(free -h | sed '1 d' | grep Mem: | awk '{print $4}') ; echo $FMEMRAM
Memoria libre del Equipo.

AMEMRAM=$(free -h | sed '1 d' | grep Mem: | awk '{print $7}') ; echo $AMEMRAM
Memoria disponible del Equipo.

TMEMSWAP=$(free -h | sed '1 d' | grep Swap: | awk '{print $2}') ; echo $TMEMSWAP
Memoria Swap total del Equipo.

UMEMSWAP=$(free -h | sed '1 d' | grep Swap: | awk '{print $3}') ; echo $UMEMSWAP
Memoria Swap usada del Equipo.

FMEMSWAP=$(free -h | sed '1 d' | grep Swap: | awk '{print $4}') ; echo $FMEMSWAP
Memoria Swap libre del Equipo.

Al run each command shown here, we will get a similar output (result), as shown in the following image:

Examples

Keep in mind that the idea with each command order is to break down what each command does within it, to see how Shell Scripting formats the output to be obtained. For example:

bash --version
bash --version | grep bash
bash --version | grep bash | awk '{print $4}'
bash --version | grep bash | awk '{print $4}' | sed 's/(//'
bash --version | grep bash | awk '{print $4}' | sed 's/(//' | sed 's/)//'
bash --version | grep bash | awk '{print $4}' | sed 's/(//' | sed 's/)//' | sed 's/-release//'
bash --version | grep bash | awk '{print $4}' | sed 's/(//' | sed 's/)//' | sed 's/-release//' | sed 's/.$//'
VBASH=$(bash --version | grep bash | awk '{print $4}' | sed 's/(//' | sed 's/)//' | sed 's/-release//' | sed 's/.$//') ; echo $VBASH
Shell Scripting – Tutorial 07: From theory to practice – Part 01
Related article:
Shell Scripting – Tutorial 07: From theory to practice – Part 01
Shell Scripting – Tutorial 06: Bash Shell Scripts – Part 3
Related article:
Shell Scripting – Tutorial 06: Bash Shell Scripts – Part 3

Abstract banner for post

In short, we hope this Tutorial 10 on «Shell Scripting» continue to offer a small but valuable contribution in terms of goal of learning and understanding the potential of Shell Scripting Technique. Also, if you want to learn a little more, I invite you to be part of this Telegram group about Shell Scripting where I also learn in Community.

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.