Search⌘ K
AI Features

Script for Managing the Contacts

Explore how to read and process contact data from a file using Bash loop constructs. Learn to avoid infinite loops and store values in associative arrays for effective contact management in scripts.

We'll cover the following...

Using read

Let’s consider that contacts.txt contains the following content.

Alice=alice@gmail.com
Bob=(697) 955-5984
Eve=(245) 317-0117
Mallory=mallory@hotmail.com

Here is an example to read the first line of the contacts.txt file. The following command does it:

read -r contact < contacts.txt

This command writes the Alice=alice@gmail.com string to the contact variable.

We ...