Populating an array in BASH

Charles Curley charlescurley at charlescurley.com
Tue Jun 23 22:52:01 MDT 2009

On Tue, 23 Jun 2009 20:49:21 -0600
Chad R Mayfield <chad at planetmayfield.com> wrote:

> On Jun 23, 2009, at 7:36 PM, Charles Curley wrote:
> > I think this used to work. Ideas?
> Works for me... something like;
> if [ $# -eq 1 ]; then
> 	array=( $(find /bin -name *at*) )
> 	echo "Elements in array: ${#array[*]}"
> 	for index in ${!array[*]}
> 	do
>      	printf "%4d: %s\n" $index ${array[$index]}
> 	done
> else
> 	echo "Nothing to see here"
> fi

Other than having to quote the operand of -name, that worked just fine.

I finally tracked down the problem. I started the script many years ago

#! /bin/sh

That works fine on Red Hat because sh is symlinked to bash. On Ubuntu
it isn't, it's symlinked to dash, another shell. I changed the shebang

#! /bin/bash

and it now works on Ubuntu. Now to check other scripts I've
written over the years. Gnrrrrr.....

Thanks for the help.


Charles Curley                  /"\    ASCII Ribbon Campaign
Looking for fine software       \ /    Respect for open standards
and/or writing?                  X     No HTML/RTF in email
http://www.charlescurley.com    / \    No M$ Word docs in email

Key fingerprint = CE5C 6645 A45A 64E4 94C0  809C FFF6 4C48 4ECD DFDB

More information about the PLUG mailing list