Day4-Shell Scripting

Day4-Shell Scripting

·

2 min read

Hello learners! Today we will be learning about Shell Scripting but before that we shall learn a few terminologies that help us understand this better.

  1. What is Kernel?

    The kernel is a computer program that is the core of a computer’s operating system with complete control over everything in the system.

  2. What is Shell?

    A shell is a special user program which provides an interface to user to use operating system services. Shell accepts human readable commands from user and convert them into something which kernel can understand. The shell gets started when the user logs in or start the terminal.

  3. What is Linux Shell Scripting?

    A shell script is a computer program designed to be run by a linux shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. In the simplest terms, shell script is a file that contains set of commands that can be executed.

  4. How is Shell scripting helpful for a DevOps engineer?

    It helps in automating most of the tasks that are handled by a DevOps engineer thereby increasing the efficiency of the work.
    A simple example of this would be a shell script which can display the system memory details of a system when executed as monitoring the system's health is one of the important responsibilities of a DevOps engineer

How to write a Shell script?

  1. Create a file with the extension .sh using vim.

  2. Make the file executable using chmod command.

  3. Be sure to add the shebang line.

    A shell script begins with #!/bin/bash which is the very first line of any shell script. This is called a "shebang" or "bang" and starts with #! followed by the path to the interpreter which is /bin/bash. If we do not specify the interpreter,

    the default is #!/bin/sh (Bash is a superset of sh, which means that Bash supports the features of sh and provides more extensions on top of that)

  4. Write the required commands needed for the script and run the file in any of the following ways given the file name is devops.sh

    1. ./devops.sh

    2. . devops.sh

    3. bash devops.sh

    4. sh devops.sh

Thanks for reading my bolg :)