Populating an array in BASH

Chad R Mayfield chad at planetmayfield.com
Tue Jun 23 20:49:21 MDT 2009


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

OUTPUT:

Mac OS X:
--------------
Elements in array: 3
    0: /bin/cat
    1: /bin/date
    2: /bin/wait4path	

Ubuntu 9.04:
------------------
Elements in array: 7
    0: /bin/zcat
    1: /bin/netcat
    2: /bin/date
    3: /bin/cat
    4: /bin/netstat
    5: /bin/bzcat
    6: /bin/ld_static


> ccurley at dragon:~$ bash --version
> GNU bash, version 3.2.48(1)-release (i486-pc-linux-gnu)
> Copyright (C) 2007 Free Software Foundation, Inc.
> ccurley at dragon:~$



On both Mac OS X

	ares: chad$ bash -version
	GNU bash, version 3.2.17(1)-release (i386-apple-darwin9.0)
	Copyright (C) 2005 Free Software Foundation, Inc.

and Ubuntu 9.04

	chad at mars:~$ bash -version
	GNU bash, version 3.2.48(1)-release (i486-pc-linux-gnu)
	Copyright (C) 2007 Free Software Foundation, Inc.


Could you perhaps add more code and maybe I could help?


---
Chad R Mayfield
chad at planetmayfield.com
GPG Key: 0C9A026F
http://www.planetmayfield.com/
http://www.chadmayfield.com/
http://www.linkedin.com/in/chadmayfield





More information about the PLUG mailing list