Table of contents
- 1. What is a kernel ?
- 2 . What is Shell?
- 3. What is Linux Shell Scripting?
- 4.Explain in your own words and examples, what is Shell Scripting for DevOps
- 5. What is #!/bin/bash? can we write #!/bin/sh as well?
- 6.Write a Shell Script that prints
- I will complete #90DaysOofDevOps challenge
- 9.Write an Example of If else in Shell Scripting by comparing 2 numbers
1. What is a kernel ?
The kernel is a core component of an operating system and serves as the main interface between the computer’s physical hardware and the processes running on it. The kernel enables multiple applications to share hardware resources by providing access to CPU, memory, disk I/O, and networking.
2 . What is Shell?
A shell is a special user program that provide an interface to user to use operating system services. Shell accepts human-readable commands from a user and converts them into something which the kernel can understand. It is a command language interpreter that executes 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. What is Linux Shell Scripting?
A shell script is a text file that contains a sequence of commands for a UNIX-based operating system. It is called a shell script because it combines a sequence of commands, that would otherwise have to be typed into the keyboard one at a time, into a single script.
A shell script is usually created for command sequences in which a user has a need to use repeatedly in order to save time. Like other programs, the shell script can contain parameters, comments and subcommands that the shell must follow. Users initiate the sequence of commands in the shell script by simply entering the file name on a command line.
4.Explain in your own words and examples, what is Shell Scripting for DevOps
In DevOps, shell scripting is used to automate a wide range of tasks such as building, testing, deploying, configuring, and monitoring software applications. For example, a DevOps engineer might use shell scripting to automate the creation of virtual machines, installation of software packages, configuration of servers, or the deployment of code to production servers.
5. What is #!/bin/bash?
can we write #!/bin/sh
as well?
#!/bin/bash
is called a shebang or a hashbang, which is a special comment used to indicate the interpreter to use for executing the script.
Yes, you can use #!/bin/sh
instead of #!/bin/bash
. The difference is that #!/bin/sh
specifies that the script should be run using the default system shell, which may or may not be the Bash shell.
6.Write a Shell Script that prints
I will complete #90DaysOofDevOps challenge
The first step is to create a file with an extension .sh
using the touch
command and then open it with any text editor of your choice . Here i will be using vim text editor.
Now we are ready to write our very first line of shell scripts command .
#! stands for shebang . #!/bin/bash is basically telling your system to use bash as a default shell.
once you are done writing your command , press esc
and write :wq
and then enter . well you have created your first shell script file. Now to run that either use bash filename.sh or ./filename.sh both will execute your file. Use chmod u+x
filename.sh to give executable permission in case it doesnt have one.
Before executing the script you have to give the +x (execute) permission to the file as chmod +x <file name>
8. Write a Shell Script to take user input, input from arguments, and print the variables.
Firstly create a file and write the script in the file
after that apply execution permission to file
chmod u+x file.txt
run the script as-
./file.sh
output -
9.Write an Example of If else in Shell Scripting by comparing 2 numbers
create a file numbers.sh and write script in that file
vim numbers.sh
change the permission of file
chmod u+x numbers.sh
Output:
that's it about shell scripting in this blog will meet in next blog
thanks for reading and do follow for such content...