Bash is the shell, or command language interpreter, for Linux operating system.

Shell - Provides an interface between the user and the kernel.

    A shell is a command-line interpreter and typical operations performed by shell scripts includes file manipulation, program execution, and printing text.

    To execute an user-defined commands we need to run a program known as shell scripts.

.sh is the extension of a shell program. And it should be an executable one(The program should have proper file permission).

    The .sh file should have the following file permission -rwxr-xr-x. To know more about file permission click here.

    All commands are not user defined. Some of the commands are builtin. There are two types of Shell commands.

Types of shell commands:

  1. Internal commands
  2. External commands
Internal commands: 

        They are known as builtin commands. It is a part of the shell itself, i.e. built into the shell.

Example:
cd, pwd, grep, etc..,.

External commands:

        Separate binaries stored in /sbin, /usr/sbin, /usr/bin, /bin, or /usr/local/bin directories. These can be find after installing an application. They can be modified.

Example: /usr/bin/java, /usr/bin/httpd, etc..,.

    All shell scripts has an Shebang #!/bin/bash

    A shebang is the first line of the file. It tells which was the interpreter to be used for execution.

    Let us see a simple shell script that will print some content.

Create a file with your text editor as myfile.sh

jhony@ljlinux:~$ vim myfile.sh

Paste the below code inside the file.

Code:

#!/bin/bash

echo We started to learn shell script!!!

Make the file an executable one:

Change the permission of the file.

jhony@ljlinux:~$ chmod +x myfile.sh

Execute the file:

Execute the file using ./ or calling the whole path of the file.

jhony@ljlinux:~$ ./myfile.sh
We started to learn shell script!!!

jhony@ljlinux:~$ sh myfile.sh
We started to learn shell script!!!

    Since we are just starting Im not going to dig deep into shell scripting now. We will start with basic operators and then working with files and directories using shell scripts and followed by installing and performing operations on applications. These all will be covered in the upcoming articles.

Basic Operators in Shell Scripting:

There are 5 basic operators in bash/shell scripting,

   1. Arithmetic Operators
   2. Relational Operators
   3. Logical Operators
   4. Bitwise Operators
   5. File Test Operators

Arithmetic Operators:
       
    These operators are used to perform normal arithmetics/mathematical operations.

Relational Operators:
       
    Relational operators are those operators which defines the relation between two operands. They give either true or false depending upon the relation.

Logical Operators:

    These are used to perform logical operations. They are also known as Boolean operators.

Bitwise Operators:

    A bitwise operator is an operator used to perform bitwise operations on bit patterns.

File Test Operator:

    These operators are used to test a particular property of a file.

    We will see in detail about these operators in shell scripts on the upcoming articles.

    In the upcoming article we will see how to use shell scripts for performing basic arithmetic operations.

Feel free to contact us if you have any questions.

Comments

  1. Be the first to add a comment.