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

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

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

In this Tutorial 09 of our current series on Shell scripting, we will continue with another set of practical examples en forma de command orders, which we started at Tutorial 07.

And keep in mind that, in the previous tutorials 07 and 08 we have been addressing the practical part of Shell Scripting using command commands to extract parameters from the OS, and in the 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 08: From theory to practice – Part 02

Shell Scripting – Tutorial 08: From theory to practice – Part 02

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

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 07: From theory to practice – Part 01
Related article:
Shell Scripting – Tutorial 07: From theory to practice – Part 01

Shell Scripting Tutorial 09

Shell Scripting Tutorial 09

Examples of commands to start in Shell Scripting

Extract values ​​and parameters related to system identification data

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

DISTROV01=$(cat /etc/os-release | grep ID | grep -v "VERSION" | cut -f2 -d\=) ; echo $DISTROV01

DISTROV02=$(cat /etc/os-release | grep ID | grep -v "VERSION_ID" | sed 's/ID=//') ; echo $DISTROV02

DISTROV03=$(lsb_release -d | sed 's/Description://' | awk '{print $1}') ; echo $DISTROV03

DISTROV04=$(lsb_release -i | awk '{print $3}') ; echo $DISTROV04

DISTROV05=$(cat /etc/os-release | grep NAME | grep -v "VERSION" | sed -n '2p' | cut -f2 -d\" | awk '{print $1}') ; echo $DISTROV05

DISTROV06=$(lsb_release -d | sed 's/Description://' | awk '{print $1, $2, $3, $4}') ; echo $DISTROV06

DISTROV07=$(cat /etc/os-release | grep NAME | grep -v "VERSION" | sed -n '2p' | cut -f2 -d\") ; echo $DISTROV07

DISTROV08=$(cat /etc/os-release | grep VERSION= | sed -n '1p' | sed 's/VERSION=//' | sed 's/"//g' | awk '{print $1}') ; echo $DISTROV08

DISTROV09=$(cat /etc/os-release | grep VERSION_ID= | sed -n '1p' | sed 's/VERSION_ID=//' | sed 's/"//g') ; echo $DISTROV09

DISTROV10=$(lsb_release -r | sed 's/Release://') ; echo $DISTROV10

DISTROV11=$(lsb_release -d | awk '{print $4}') ; echo $DISTROV11

DISTROV12=$(lsb_release -c | sed 's/Codename://') ; echo $DISTROV12

DISTROV13=$(cat /etc/os-release | grep VERSION= | sed -n '1p' | sed 's/VERSION=//' | sed 's/"//g' | awk '{print $2}' | sed 's/(//g' | sed 's/)//g') ; echo $DISTROV13

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

Extract values ​​and parameters related to system identification data

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. In such a way, to understand each step of the executed command order. For example, with the first example, the idea would be to execute everything as follows:

cat /etc/os-release
cat /etc/os-release | grep ID
cat /etc/os-release | grep ID | grep -v "VERSION"
cat /etc/os-release | grep ID | grep -v "VERSION" | cut -f2 -d\=
DISTROV01=$(cat /etc/os-release | grep ID | grep -v "VERSION" | cut -f2 -d\=) ; echo $DISTROV01
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

Abstract banner for post

In short, we hope this Tutorial 09 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. And if you want to learn a little more, I invite you to explore the following YouTube channel, where regularly addresses in a practical way the power of shell scripting through technical and educational tool call LPI-SOA (Linux post Install – Advanced Optimization Script).

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.