"Shell Scripting: Automate Your Tasks with Ease!"

"Shell Scripting: Automate Your Tasks with Ease!"

  • Explain in your own words and examples, what is Shell Scripting for DevOps.

Shell Scripting for DevOps is a scripting language used to automate tasks and processes in a DevOps environment. These scripts can be used to deploy applications, manage servers, install software, and perform other operations. Examples of shell scripts include installing a web server, automating database backups, and setting up a continuous integration pipeline. Shell scripts help DevOps engineers streamline their workflows and save time on repetitive tasks.

  • What is #!/bin/bash?

#!/bin/bash is a shebang. It is a special type of comment that tells the operating system which interpreter to use when executing a script. It is often used at the beginning of a Bash script to indicate that the script should be run with the Bash interpreter.

  • Can we write #!/bin/sh as well?

Yes, you can write #!/bin/sh as well. This is known as a shebang line and it is used to tell the operating system which program should be used to execute the script. The #!/bin/sh shebang line is used to tell the system to use the Bourne shell (sh) to interpret the script.

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

Open the terminal and type the following command

$ nano 90DaysOfDevOps.sh

Then write the following script

#!/bin/bash -shebang

echo "I will complete #90DaysOfDevOps challenge."

Save the file by pressing 'Ctrl+X' and pressing 'Y' to save the changes.

Run the shell script by typing the following command

$ ./90DaysOfDevOps.sh

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

1. The first line of the shell script is the shebang line which tells the interpreter which program should be used to execute the program.

2. The next two lines define two variables, a and b.

3. The following line is the if statement, which checks if a is greater than b.

4. If the condition is true, then the echo command prints "A is biggest".

5. If the condition is false, then the else statement is executed, which checks if b is greater than a. 6. If the condition is true, then the echo command prints "B is biggest".

Then, Press ctrl+x to exit and press Y to save the progress and press ENTER.

Then run the shell script in the Terminal to see the result

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

  1. This shell script will first print out a message saying "What is your name?"

  2. It will then prompt the user to enter their name and store it in a variable named "name".

  3. Next, it will print out a message saying "My name is [name]"

  4. Finally, it will print out a message saying "Nice to meet you, [name]"

  5. while running the file in the terminal you must first proceed by typing the argument along with the file name. For example - ./test.sh argument. Here, the argument is my name, Amit

Thank you so much for taking the time to read my blog! Your support means the world to me and I'm so grateful for it.