4/13/2020

Shell Scripting

** Shell Scripting


- Hardware - Kernel - Operating System - Shell - Terminal - User


` Types of Shell

- POSIX shell also known as sh

- Korn Shell also known as sh

- Bourne Again SHell also known as bash

- C shell also known as csh

- Tops C shell also known as tcsh


` What is shell scripting and why do I need it?

- Writing a series of commands

- Combine lengthy and repetitive commands

- This helps reduce the efforts


` Creating a Shell script

1. Create a file using a text editor like vi

2. Name script file with extension .sh

3. Start the script with #! /bin/sh

4. Write some code

5. Save the script file as filename.sh

6. For executing the script type bash filename.sh


` Adding shell comments

- # comment

` What are Shell Variables?

ex)
variable = "Hi"
echo $variable

Hi

ex)
#! /bin/sh
echo "What is your name?"
read name
echo "How do you do, $name?"
read remark
echo "I am $remark too!"



`` Summary

- Kernel is the nucleus of the operating systems and it communicates between hardware and software.

- Shell is a program which interprets user commands through CLI like Terminal.

- The Bourne shell and the C shell are the most used shells in Linux.

- Shell scripting is writing a series of command for the shell to execute.

- Shell variables store the value of a string or a number for the shell to read.

- Shell scripting can help you create complex programs containing conditional statements, loops and functions.