DevOps(Day-4)

DevOps(Day-4)

Shell scripting in LINUX

  1. What is Shell Scripting?

    It is a set of commands written in an executable file to automate any task. The commands are converted then to machine-readable form to execute.

    Syntax:-

    #!/bin/bash

    <commands>

    The file to be created must be with extension ".sh" and provided with necessary execute permissions to the user running the script.

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

    #! is called Shebang. It contains the path (/bin/bash) which uses the shell for executing the code written in the script file.

    BASH - Bourne again shell

    /bin/bash can execute the majority of scripts thus it is used widely.

    /bin/sh is an executable representing the system shell and is usually implemented as a symbolic link pointing to the executable for whichever shell is the system shell. The system shell is the default shell that the script should use.

    Basically, it points to /bin/bash but nowadays it became /bin/dash which is faster.

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

    vim first_script.sh


#!/bin/bash

echo "I will complete #90DaysOofDevOps challenge"


Chmod 777 first_script.sh

./first_script.sh

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

#!/bin/bash

echo "Hello I am $1"

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

    #!/bin/bash

    a=5

    b=8

    if [[ $a -gt $b ]]

    echo "a is greater than b"

    else

    echo"b is greater than a"