bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Array declaration doesn't seem to work properly in Ver 3.2**SOLVED"*


From: Jim Adamson
Subject: RE: Array declaration doesn't seem to work properly in Ver 3.2**SOLVED"**
Date: Tue, 11 Nov 2008 03:52:40 -0500

My problem was with "sh" not "bash"! I was initiating the script
incorrectly.
Pierre Gaston pointed out my mistake and it works fine now.
Sorry for the alarm and my stupidity!
Best,
Jim




-----Original Message-----
From: Jim Adamson [mailto:jca5@elktalk.com] 
Sent: Monday, November 10, 2008 2:11 PM
To: 'bug-bash@gnu.org'; 'bash@packages.debian.org'
Subject: Array declaration doesn't seem to work properly in Ver 3.2

From: jim5@elktalk.com
To: bug-bash@gnu.org,bash@packages.debian.org
Subject: Array declaration doesn't seem to work properly in Ver 3.2

Configuration Information [Automatically generated, do not change]:
Machine: i486
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i486'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL
-DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib   -g -O2
-Wall
uname output: Linux Demos 2.6.22-15-generic #1 SMP Tue Oct 21 23:47:12 GMT
2008 i686 GNU/Linux Machine Type: i486-pc-linux-gnu

Bash Version: 3.2
Patch Level: 25
Release Status: release

Description:
        Declare: not found error
        read: -a  illegal option
I have two machines running Bash ver. 3.2 and one running 3.1.  I get the
above errors always on the 3.2 boxes but not the 3.1 box.

statements that cause the problem are:
declare -a arrayname
read -a arrayname

Repeat-By:
        here is a test script that repeats the errors:
____________________________________________________________________________
____________________________________
#!/bin/bash

declare -a colors
# Permits declaring an array without specifying size.

echo "Enter your favorite colors (separated from each other by a space)."

read -a colors
# Special option to 'read' command,
# allowing it to assign elements in an array.

echo

  element_count=${#colors[@]} # Special syntax to extract number of elements
in array.
# element_count=${#colors[*]} works also.
index=0

# List all the elements in the array.
while [ $index -lt $element_count ]
do
  echo ${colors[$index]}
  let "index = $index + 1"
done
# Each array element listed on a separate line.
# If this is not desired, use  echo -n "${colors[$index]} "

echo

# Again, list all the elements in the array, but using a more elegant
method.
  echo ${colors[@]}
# echo ${colors[*]} works also.


echo

exit 0
____________________________________________________________________________
_________________________________________

Fix:
        I sure wish I knew!!  if you can help me figure out why this works
on one machine but not the two with newer versions
        could you please let me know.

        Thanks,
        Jim Adamson
        jim5@elktalk.com





reply via email to

[Prev in Thread] Current Thread [Next in Thread]