Scripting Classroomnotes 08/Feb/2023

Exploring the if then else

  • If the else
if command
then
    commands
else
    commands
fi
  • if then elif
if command
then
    commands
elif command2
then
    commands
fi

Functions

  • A reusable block of code is called as function
  • Lets write a reusable code to get the distribution
#!/bin/bash


# function definition to get distribution
get_distribution() {
    distribution=""
    # Check if /etc/os-release  file exists
    if [ -r /etc/os-release ]; then
        distribution="$(. /etc/os-release && echo "$ID")"
    fi
    echo $distribution

}

# usage
echo $(get_distribution)

  • refer here for function
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Plugin for Social Media by Acurax Wordpress Design Studio

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%