BASH – Read A File, One Line At A Time

Disclaimer

The instructions/steps given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.com, nor its author is responsible for any/all damage – intellectual or otherwise.


What is BASH?

BASH is a free software Unix shell written for the GNU Project. Its name is an acronym which stands for Bourne-again shell. The name is a pun on the name of the Bourne shell (sh), an early and important UNIX shell written by Stephen Bourne and distributed with Version 7 UNIX circa 1978, and the concept of being born again. BASH was created in 1987 by Brian Fox. In 1990 Chet Ramey became the primary maintainer. BASH is the default shell on most GNU/Linux systems as well as on Mac OS X and it can be run on most UNIX-like operating systems. It has also been ported to Microsoft Windows using the POSIX emulation provided by Cygwin, to MS-DOS by the DJGPP project and to Novell NetWare.


The Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#! /bin/bash
 
# Read one line at a time from a specified file. 
# Can be used to extract required information from those lines.
#
# Usage: ./read-lines.sh FILENAME 
# Mon, 23 Jun 2008 22:24:24 -0400
 
echo
exec<$1
 
while read line
do
  echo $line
done
 
echo