Shell Script: Read File Line by Line

Objective: Read the contents of a file line by line in a shell script.

The following block of code will read a file (referenced by variable $input_file) line by line from top to bottom and store the contents of the currently read line into a variable called $line. In the input file, each line has to be terminated by a newline (‘\n’) character.

The variable IFS is set to an empty string to prevent the read command from removing the leading and trailing whitespace characters.

The “-r” option to read command makes sure that it will not interpret backslash as an escape character.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react, vuejs); plays_on(xbox, ps4); linux_desktop_user(true); }

« Previous Article