From owner-freebsd-questions@FreeBSD.ORG Wed Jul 15 01:57:25 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 83A321065672 for ; Wed, 15 Jul 2009 01:57:25 +0000 (UTC) (envelope-from jhall@socket.net) Received: from mf5.socket.net (mf5b.socket.net [216.106.26.210]) by mx1.freebsd.org (Postfix) with ESMTP id 2AE788FC12 for ; Wed, 15 Jul 2009 01:57:24 +0000 (UTC) (envelope-from jhall@socket.net) Received: from [10.129.40.202] (216.106.12.14.reverse.socket.net [216.106.12.14]) by mf5.socket.net (Postfix) with ESMTP id 054BA64C21 for ; Tue, 14 Jul 2009 20:57:23 -0500 (CDT) Message-Id: <4A48C83B-A36C-417F-9F68-F1CB1BCDDC8F@socket.net> From: Jay Hall To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v935.3) Date: Tue, 14 Jul 2009 20:57:23 -0500 X-Mailer: Apple Mail (2.935.3) Subject: Bash and arrays X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jul 2009 01:57:25 -0000 Ladies and Gentlemen, I thought I understood how arrays work in bash, but I have been proven wrong. I am reading lines from a file and placing them in an array. However, when I am finished, the array has a length of 0. Following is the code I am using. #!/usr/local/bin/bash COUNTER=0 cat ./test_file.txt | while read LINE do echo ${LINE} FOO[${COUNTER}]=${LINE} COUNTER=`expr ${COUNTER} + 1` done echo ${#FOO[@]} echo ${#FOO[*]} And, here is the output. test_file file_size 0 0 Thanks in advance for any help you can offer. Jay