Day:-4 Task

Day:-4 Task

Shell Scripting

Task:-

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

  2. What is #!/bin/bash? can we write #!/bin/sh as well?

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

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

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

Answer:-

  1. The shell script is part of the automation process in Linux, where we use a set of Linux commands and execute them to perform specific tasks. A shell script may include comments, where we can describe the steps. It starts with “#!/bin/bash”. Operations, that we may perform with the help of Shell Script are file manipulations, text operations & printing, and many more. Each Shell Scripting file will have a “.sh” extension, e.g. “file1.sh” Example:-

    Go to terminal git bash type vim file1.sh#!/bin/bash

    echo "Hello world"

    echo "My name is Amit Kumar"

    save:- press keyboard <esc> then <:wq>

    chack file1.sh print:- cat file1.sh, ls-la to check file permission, chmod 777 file1.sh

    ./file1.sh - this command shows my file content print.

  2. #!/bin/bash is known as shebang. Script files use the shebang line “#!/bin/bash” to set bash.

    Yes, we can use #!/bin/sh. “bash” and “sh” are two different shells. Bash is sh, with more features and better syntax.

  3. Script:

    #!/bin/bash

    echo “90DaysOfDevOps challenge”

  4. Script:

    #!/bin/bash

    echo "Hello, I am Jarvis! What is your name?"

    read var name

    echo "Nice to meet you $var name"