Skip to main content

Command Palette

Search for a command to run...

Basic Linux Shell Scripting .

Published
3 min read
Basic Linux Shell Scripting .

What is Kernel:

The kernel is a computer program that is the core of a computer’s operating system, with complete control over everything in the system.

What is Shell:

A shell is a special user program that provides an interface for users 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.

What is Linux Shell Scripting?

A shell script is a computer program designed to be run by a linux shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing text.

What is Shell Scripting for DevOps?

Shell scripting is a process of creating a set of commands in a file that can be executed to perform repetitive or routine tasks automatically, without the need for manual intervention. As a DevOps engineer, shell scripting can be a powerful tool for automating various tasks such as server configuration, deployment, monitoring, and maintenance.

What is #!/bin/bash? Can we write #!/bin/sh as well?

The shebang, #!/bin/bash when used in scripts is used to instruct the operating system to use bash as a command interpreter. Each of the systems has its own shells which the system will use to execute its own system scripts. This system shell can vary from OS to OS(most of the time it will be bash). Whereas, when the shebang, #!/bin/sh used in scripts instructs the internal system shell to start interpreting scripts.

/bin/sh and /bin/bash are both Unix/Linux shell interpreters, but they have some differences in their behavior and syntax. /bin/sh is a POSIX-compliant shell that is designed to be small and efficient, while /bin/bash is a more feature-rich shell that includes many additional features and extensions.

For example, some features such as arrays and some string operations are not available in /bin/sh, but they are available in /bin/bash. Additionally, /bin/bash provides more extensive support for interactive shell features such as command history, auto-completion, and job control.

We can write #!/bin/sh in place of #!/bin/bash, the difference is just in shells 'sh' means Bourne Shell and 'bash' means Bourne Again Shell. Bash shell scripting is a kind of shell scripting only. You can say, it's a subset of shell scripting. The Bourne Shell is another commonly used shell in Unix-based operating systems.

Write a Shell Script that prints I will complete #90DaysOofDevOps challenge.

after executing nano pratu.sh command write

#!/bin/bash
echo " I will complete #90DaysofDevops"
Press ctrl+O and ctrl+x .Then you will come out of the file after that execute
bash pratu.sh to see the output.

Write a Shell Script to take user input, input from arguments and print the variables.

nano input.sh : after pressing enter button it will open the input.sh file.
then write,

#!/bin?bash
echo" My name is $1 $2 "

Write an Example of If else in Shell Scripting by comparing 2 numbers :

Thank you for Reading!

Pratibha Yedle