3
# A more elaborate version of fetch_address.sh.
6
E_DB=99 # Error code for missing entry.
9
# -A option declares associative array.
21
if [[ -z "${address[$1]}" ]]
23
echo "$1's address is not in database."
27
echo "$1's address is ${address[$1]}."
32
store_address "Lucas Fayne" "414 W. 13th Ave., Baltimore, MD 21236"
33
store_address "Arvid Boyce" "202 E. 3rd St., New York, NY 10009"
34
store_address "Velma Winston" "1854 Vermont Ave, Los Angeles, CA 90023"
36
# Rewrite the above store_address calls to read data from a file,
37
#+ then assign field 1 to name, field 2 to address in the array.
38
# Each line in the file would have a format corresponding to the above.
39
# Use a while-read loop to read from file, sed or awk to parse the fields.
41
fetch_address "Lucas Fayne"
42
# Lucas Fayne's address is 414 W. 13th Ave., Baltimore, MD 21236.
43
fetch_address "Velma Winston"
44
# Velma Winston's address is 1854 Vermont Ave, Los Angeles, CA 90023.
45
fetch_address "Arvid Boyce"
46
# Arvid Boyce's address is 202 E. 3rd St., New York, NY 10009.
47
fetch_address "Bozo Bozeman"
48
# Bozo Bozeman's address is not in database.
50
exit $? # In this case, exit code = 99, since that is function return.