Read file line by line?

Shell Script to Read File Brief: This example will help you to read a file in a bash script. This tutorial contains two methods to read a file line by line using a shell script. Method 1 – Using simple loop You can use while read loop to read a file content line by line and store into a variable.

Note – In above script line is a variable only. You can use any variable name in place of the line of your choice. Method 2 – Using IFS…

Read More

Bash – Functions

Functions in Bash A function which can also be referred to as subroutine or procedure is a block of code used for specific tasks. The function also has a property called re-usability. Bash script also provides functions. Syntax: funcationName(){ // scope of function } functionName //calling of function #1. Bash – Create Function Example Create your first function in shell script showing output “Hello World!”. Create a shell script “script.sh” using following code. #!/bin/bash funHello(){ echo “Hello World!”; } # Call funHello from anywhere in the script like below funHello…

Read More

Bash – For Loop

For Loop in Bash As any other programming language, shell scripts also support for loops to do the repetitive tasks. Read this tutorial to understand uses of for loop with examples. Syntax: for VARIABLE in PARAM1 PARAM2 PARAM3 do // scope of for loop done for loop executes for each parameter once defined. The VARIABLE is initialized with the parameter’s value which can be accessed in inside the for loop scope. These parameters can be any number, string etc. #1. Bash – For Loop Example Check below basic for loop…

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