Bash – Arithmetic Operations

Bash Arithmetic Operations You can perform arithmetic operations on numeric values in bash scripts. You can find many options to perform arithmetic operations on bash shell but below example will provide you simplest way. Syntax: ((expression)) ((var1+var2)) ((var1-var2)) ((var1*var2)) ((var1/var2)) Bash Arithmetic Operations Example: For example, take an input of two numeric values and perform all 5 basic arithmetic operations like below:

Increment and Decrement Operator: Bash also used incremnt (++) and decrement (–) operators. Both uses in two types pre-increment/post-increment and pre-decrement/post-decrement.

Similarly, try pre-decrement and post-decrement…

Read More

Bash – User Input

User Input In Bash Linux read command is used for interactive user input in bash scripts. This is helpful for taking input from users at runtime. Syntax: read [options] variable_name Example 1: There is no need to specify any datatype for the variables with the read operation. This simply takes an input of any data type values. Try with a sample command. Open bash shell terminal and type following command. read myvar The above command will wait for user input. so just type anything and press enter. Let’s create a…

Read More

Bash – Command Arguments

Command Line Arguments in Shell Script Command line arguments are also known as positional parameters. These arguments are specific with the shell script on terminal during the run time. Each variable passed to a shell script at command line are stored in corresponding shell variables including the shell script name. Synatx: ./myscript.sh ARG1 ARG2 ARG3 ARG4 ARG5 ARG6 ARG7 ARG8 ARG9 ARG10 See the below image to understand the command line values and variables. Here ARG1, ARG2 to ARG10 are command line values, which is assigned to corresponding shell variables.…

Read More

Bash – Quotes

Quotes in Bash This is a standard practice to quote the string in any programming language. Quotes are used to deal with the texts, filenames with a space character. Read this tutorial to understand the differences between single quote and double quotes. Quote with String While working with simple texts and string, there are no different in using a single quote or double quote.

The above script will run without any error and print the messages and create both directories. Quote with Variables Just remember that the shell variable…

Read More

Bash – Variables

Variables in Bash The bash variables are the same as other programming languages. You don’t need to specify the type of variable in bash scripting. Read below example. #!/bin/bash NAME=”TecAdmin Tutorials” echo $NAME launchdate=”Feb 08, 2013″ echo $launchdate Global vs Local Variables Global variables are accessible anywhere in the script. Where Local variables are accessible in scope only. For example, a variable that is used inside a function only.

System Variables System variables are responsible to define the aspects of the shell. These variables are maintained by bash itself.…

Read More

Bash Tutorial

Shell scripting

Shell Scripting The Bash (Born Again) is a Unix shell and command line language written by the Brian Fox. The Born Again shell is used by most of the Unix/Linux operating systems as there default shell. This Shell Script tutorial is written for the peoples want to learn the basics of shell script programming (Shell scripting). In this series of tutorials, you will learn about bash scripting, which is very useful for automating the daily tasks, larger tasks easier. It helps to automation of tasks like backups, disk cleanup etc.

Read More