bug-gnu-utils
[Top][All Lists]
Advanced

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

Possible bug with shell arrays


From: gerd . niemetz
Subject: Possible bug with shell arrays
Date: Mon, 11 Dec 2006 13:54:32 +0100

Hi!

When trying to get the contents of shell array's nothing happens. Is this 
a bug?
Run the following sample:

#!/bin/bash
set -a
SOMETEXT="This is a test"
SOMEARR[1]="This "
SOMEARR[2]="is "
SOMEARR[3]="the "
SOMEARR[4]="next "
SOMEARR[5]="test"
CNT_ARR=${#SOMEARR[*]}
set +a

for (( CNT=1; CNT<=${CNT_ARR}; CNT++ ))
do
  echo "in shell - \${SOMEARR[${CNT}]}: ${SOMEARR[${CNT}]}"
done
echo "++++++++++++++"

gawk -v cnt="${CNT_ARR}" 'BEGIN {
for (env in ENVIRON)
                print env "=" ENVIRON[env]
print "++++++++++++++"
printf "system - ${SOMEARR[1]}: "
system("echo ${SOMEARR[1]}")
print "++++++++++++++"
printf "system - ${SOMETEXT}: "
system("echo ${SOMETEXT}")
print "++++++++++++++"
for( i = 1; i <= cnt; i++ ) {
  cmd = "echo ${SOMEARR[" i "]}"
  printf "getline - " cmd ": "
  cmd | getline text
  print text
  }
}'

best regards
Gerd Niemetz


reply via email to

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