2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018

03/01/2003: Using Hashes in Bash Scripts

Using Hashes in Bash Scripts

This codebit was donated by Phil Howard on 1998Dec03. Hash data structures are very convenient. They let you use strings as indexes instead of numbers. The value script, shown below, demonstrates how to use Bash's eval command to simulate a hash structure. The command, value david prints "The email address for david is medined@mtolive.com".

#!/bin/bash
# value.sh

email_phil="phil@rigel.ipal.net"
email_david="medined@mtolive.com"

eval 'email=${email_'"${1}"'}'
echo "The email address for ${1} is ${email}"


subscribe via RSS