Shell Scripting Part 3

Before you read the Shell Scripting Part 3, go through my previous blogs on Shell Script.

Shell Scripting One

Shell Scripting Two

Today let's understand the arithmetic operation in Shell Scripting.

After reading the above line and previous blogs we don't have specific data types available but can we do the arithmetic operation in Shell Scripting too?

You are right, we can do it!

We have expr the keyword which will help us to perform arithmetic operations.

Let's say I want to add two numbers, how I can write?

One of the important commands which help Shell Scripting makes it more interactive i.e read command.

Syntax: read <Variable_Name>

Note: If we don't specify the <variable-name> by default it will take an inbuilt variable i.e $REPLY.

Is Shell Script supports Arrays?

Yes, it will support the Arrays with the -a option along with the read command. Now what is an array?

The array is a collection of data, and that data will store memory location.

Note: Whenever you receive the error Illegal option read -a. You were trying to run the command in the Bourne shell the command sh array_example.sh and the Bourne shell read doesn't have the -a option for reading. It's a Bash feature. So the script with bash.

In most of the programs that I wrote here you are seeing that the read command is taking the input from the next line but I want to take the input from the same line. We have the option -p that helps us to take the input from the same line.

Let's say that I want to take the input as a password from the user and I don't want to see the password entered by the user. We can do with -sp option.

-sp - secure

Please follow me for more information about the DevOps Topic and tools with detailed examples and usage.

If you have any feedback, you can send it to .