Shell Scripting Basic for DevOps Engineer

Shell Scripting Basic for DevOps Engineer

What is Kernel?

Kernel is central component of an Operating system that manages hardware resources and system operations. Generally has complete control over everything in the system.

What is Shell and Shell Scripting?

Shell is a user interface to use operating system services by executing commands. It allows a user to give commands to the kernel and receive responses from it.

Shell Scripting is a text file that contains series of commands executed by shell that instructs the operating system to perform certain tasks.

Shell Scripting Tutorial

To determine the path of the bash executable file:

which bash

location of the Bash executable

To display a line of text to the terminal:

echo

To create a shell script text file:

nano devops.sh

To execute your shell script:

bash devops.sh

execute script

Changing file permissions through octal mode:

chmod 744 filename

To execute the script named devops.sh located in the current directory (./ denotes the current directory in Unix-like operating systems):

./filename.sh

to execute script in the current directory

To print variables in a shell script:

name="Muzammil"
echo "Hi this is ${name}"

To add comments in a bash script, use ‘#' :

#echo $BASH

to add comments

To take user input:

read variable
echo "$(variable)"

take user input

To pause the execution of the script for a specified amount of time:

sleep NUMBER[SUFFIX]
# Example: sleep 5s (for 5 seconds)

pause the execution of script

To take user arguments, add a $ sign to your script along with a number to make a sequence of arguments:

user argument

To execute a script with user arguments:

execute user argument script

Code for an if-else statement (end with fi):

code for if-else

To learn more click on the given link

how to write a bash script

changing file permissions in octal mode