Tasks
🔹Explain in your own words and examples, what is Shell Scripting for DevOps.
🔹What is #!/bin/bash?
can we write #!/bin/sh
as well?
🔹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.
🔹 what is Shell Scripting for DevOps?
▪A shell script is a file containing a series of commands. The shell reads this file and carries out the commands as though they have been entered directly on the command line.
▪Normally the shell scripts have the file extension .sh
▪To create a shell script, you use a text editor. There are many text editors available for Linux systems for both command-line environments and GUI environment
vi and vim is command-line environments.
gedit is a GUI environment.
There are several shells are available for Linux systems like –
BASH (Bourne Again SHell) – It is most widely used shell in Linux systems. It is used as default login shell in Linux systems and in macOS. It can also be installed on Windows OS.
CSH (C SHell) – The C shell’s syntax and usage are very similar to the C programming language.
KSH (Korn SHell) – The Korn Shell also was the base for the POSIX Shell standard specifications etc.
🔹What is #!/bin/bash?
can we write #!/bin/sh
as well?
▪ #!/bin/bash is known as shebang in Unix. Shebang is a collection of characters or letters that consist of a number sign and exclamation mark, that is (#!) at the beginning of a script.
▪ 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 shells which the system will use to execute its 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. so that, we can use #!/bin/sh as well.
File colour:
Executable scripts appear in a different color from rest of the files and folders. scripts with execution rights appear as green.
🔹Write a Shell Script that prints I will complete the #90DaysOofDevOps challenge
#!/bin/bash
echo "I will complete the #90DaysOofDevOps challenge"
🔹Write a Shell Script to take user input, input from arguments and print the variables.
#!/bin/bash
# user inuput
read -p "Enter your name: "name
#Print the variables
echo "Hello $name! welcome to shell script!"
🔹Write an Example of If else in Shell Scripting by comparing 2 numbers
Here I am taking 2 numbers as num1=10, and num2=20
num1=10
num2=20
if [$num1 -gt $num2 ];
then echo "$num1 is greater than $num2"
elif [$num1 -lt $num2 ];
then echo "$num1 is less than $num2"
else
echo "$num1 is equal to $num2"
fi
Thanks for reading to the end; I hope you gained some knowledge.❤️🙌