#devops 4
Table of contents
- INTRODUCTION TO BASIC LINUX.
- What is #!/bin/bash? can we write #!/bin/sh as well?
- #!/bin/bash is an All the shell scripts start with the #!/bin/bash command. In the case of #!/bin/bash, it denotes that the Bash shell should be used to run the script. The operating system will utilize the Bash interpreter (/bin/bash) to interpret and carry out the commands in the script when you run it with this shebang. The shebang line is essential because it ensures that the script is executed using the correct interpreter, regardless of your current shell or environment. It allows you to write scripts in various scripting languages and ensure they're executed with the intended interpreter.
- Write a Shell Script that prints I will complete the #90DaysOofDevOps challenge
- Write a Shell Script to take user input, input from arguments and print the variables.
- Write an Example of If else in Shell Scripting by comparing 2 numbers
- THIS IS A SOME BASIC INFORMATION ABOUT TERRAFORM.
- THANK YOU FOR WATCHING THIS BLOG AND THE NEXT BLOG COMING SOON
Hello, everyone, this is my 4 blog . From this blog, I want to share my 4th-day experience OR some information on Basic Linux Shell Scripting for DevOps Engineers. with you.
#linux #trainwithshubham #shubhamlondhne
INTRODUCTION TO BASIC LINUX.
Lists of contents.
Explain what Shell scripting for DevOps is in your own words and examples.
What is
#!/bin/bash?
can we write#!/bin/sh
as well?Write a Shell Script that prints
I will complete #90DaysOofDevOps challenge
Write a Shell Script to take user input, input from arguments and print the variables.
Write an Example of If else in Shell Scripting by comparing 2 numbers
LETS START WITH SOME INTERESTING INFORMATION
Explain what Shell scripting for DevOps is in your own words and examples.
Shell scripting is a powerful skill that allows you to automate various tasks, manage systems, and perform routine operations. Let's start with the fundamentals:
Open shell:- The most well-known and extensively used shell on Linux is Bash (Bourne Again SHell). For your scripting requirements, you should probably use Bash. Use the echo $SHELL command to determine your current shell's status.
Creating And Running a Script:- Shell scripts are text files that contain a list of commands. Their typical file extension is. sh. You can use a text editor like Nano, vim, or Gedit to write a new shell script.
let's take some basic examples of shell Script named As "Devops. sh"
#!/bin/bash
echo "Hello, DevOps!"
All the shell scripts start with the #!/bin/bash command. In the case of #!/bin/bash, it denotes that the Bash shell should be used to run the script. The operating system will utilize the Bash interpreter (/bin/bash) to interpret and carry out the commands in the script when you run it with this shebang.
variables:- We want to access some variable value we use
$ sing
. You can Declare and use variables in shell scripts. Variables are case-sensitive and should not start with a number.name="John"
echo "Hello, $name!"
Input & Output:- You can interact with the user by reading input And Output
echo "What's your name?"
read username
echo "Hello, $username!"
Command & Arguments:- we can also pass arguments with a shell script like,
echo "First argument: $1"
echo "Second argument: $2"
when we want to access some arguments we use
$1 &$2
$#
is used to count the arguments.$@
is used for multiple arguments
What is
#!/bin/bash?
can we write#!/bin/sh
as well?
#!/bin/bash
is an All the shell scripts start with the #!/bin/bash command. In the case of #!/bin/bash, it denotes that the Bash shell should be used to run the script. The operating system will utilize the Bash interpreter (/bin/bash) to interpret and carry out the commands in the script when you run it with this shebang. The shebang line is essential because it ensures that the script is executed using the correct interpreter, regardless of your current shell or environment. It allows you to write scripts in various scripting languages and ensure they're executed with the intended interpreter.
#!/bin/sh
The Bourne shell (sh) or a comparable shell, such as the Bourne Again Shell (bash) or the Debian Almquist Shell (dash), is often the system's default shell interpreter, and /bin/sh points to that shell. On several Unix-like systems, the shell that /bin/sh represents may be different. When you use #!/bin/sh as a script's shebang line, you're instructing the default shell interpreter to run the script. This method can be applied to scripts that are meant to run on various Unix-like platforms more easily. However, be aware that several shell interpreters may have slightly different behavior or syntax. Because of this, while using #!/bin/sh can improve portability, you may want to avoid using shell-specific capabilities if you want your script to function consistently on different systems.
Write a Shell Script that prints
I will complete the #90DaysOofDevOps challenge
This is the shell script for printing I will complete #90DaysOofDevOps challenge:-
#!/bin/bash
echo "I will complete #90DaysOfDevOps challenge"
Here are the script's actions:
A Shebang that specifies the interpreter, in this case, BASH, is #!/bin/bash.
echo: a printing tool for messages.
Activate the script by:
The code should be saved as my_script.sh.
chmod +x my_script.sh to make it executable.
after that run the script./my_script.sh
Write a Shell Script to take user input, input from arguments and print the variables.
This is the shell script to take user input, input from arguments and print the variables
This script can be put into a file, made executable, and then executed. The script will ask you for your name when you run it, and you can also execute the script with two command-line options. The script will then print the values of the variables.
Write an Example of If else in Shell Scripting by comparing 2 numbers
Here is a description of how the script functions:
The shebang line specifies that this is a Bash script by writing #!/bin/bash.
Two variables, number1 and number2, are defined, and their respective values are 10 and 20, respectively.
Conditional execution is accomplished using the if-else expression. The operators -gt (greater than) and -lt (less than) are used to compare numbers 1 and 2.
Whenever number 1 exceeds number 2, the first block of code is run. This statement is printed using the echo command: "$number1 is greater than $number2."
The script compares whether the number1 is smaller than number in the elif (else if) condition if the number1 is not higher than the number. The appropriate piece of code is performed if this condition is true, printing the.