Basic Linux Shell Scripting for DevOps Engineers.
When we are using any major operating system, we are indirectly interacting with the?shell. While running Ubuntu, Linux Mint, or any other Linux distribution, we are interacting with the shell by using the terminal.?
Before that one of the basic things, you should know is the architecture of LINUX.
The diagram illustrates the structure of the Linux system, according to the layers concept.
The main components of Linux operating system are?-Application, Shell, Kernel, Hardware, Utilities.
2. Shell: A shell is special user program which provide an interface to user to use operating system services. Shell accepts human readable commands from user and convert them into something which kernel can understand. It is a command language interpreter that execute commands read from input devices such as keyboards or from files. The shell gets started when the user logs in or start the terminal.
3. Hardware Layer: Hardware layer of Linux is the lowest level of operating system track. It is plays a vital role in managing all the hardware components. It includes device drivers, kernel functions, memory management, CPU control, and I/O operations.
4.?System utility: System utilities are the commend line tools that preforms various tasks provided by user to make system management and administration better. These utilities enable user to perform different tasks, such as file management, system monitoring, network configuration, user management etc.
What is #!/bin/bash? Can we write #!/bin/sh as well?
The line #!/bin/bash is known as a shebang (or hashbang). It is used at the beginning of a script to specify the interpreter that should be used to execute the script. In this case, #!/bin/bash indicates that the script should be run using the Bash shell, which is located at /bin/bash.
Yes, you can write #!/bin/sh as well. This shebang line indicates that the script should be run using the sh shell, which is typically a link to a POSIX-compliant shell. The exact shell that /bin/sh points to can vary between systems; on many systems, it points to a lightweight shell like dash (Debian Almquist Shell) for performance reasons, but it could also be a link to bash or another shell.
Here's a brief comparison of the two:
领英推荐
Using #!/bin/sh is recommended if you want your script to be portable and compatible with different Unix-like operating systems, while #!/bin/bash is preferred if you need specific features provided by Bash.
What is Linux Shell Scripting?
Linux shell scripting involves writing programs (scripts) that can be run by a Linux shell, such as bash (Bourne Again Shell). These scripts automate tasks, perform system administration tasks, and facilitate the interaction between users and the operating system.
?Let do some hand-ons in LINUX based on this topic:- So here are the tasks we will be doing today:-
For this we will create one empty file with .sh extension and using vim editor we will use echo command to print 'I will complete #90DaysOofDevOps'. We will give all the permission for execution by using chmod command - chmod 775 file name. Then we will execute it by using ./filename. Refer the picture down to see all the commands in series which i used to print the message.
2. Write a Shell Script to take user input, input from arguments and print the variables. OR Write an Example of If else in Shell Scripting by comparing 2 numbers.
This script will accept the two command line input from user and tell which number is greater.
?Conclusion:-Shell scripting is an essential skill for any DevOps professional. It enables us to automate tasks, manage systems efficiently, and handle complex workflows with ease. By mastering the basics of shell scripting, we're laying a strong foundation for our DevOps journey. Keep practicing and experimenting with different scripts to enhance your skills. Stay tuned for more exciting lessons