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

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

Re: Possible bug with shell arrays


From: Aharon Robbins
Subject: Re: Possible bug with shell arrays
Date: Thu, 04 Jan 2007 20:35:39 +0200

Greetings.

Shell arrays are not exported into the environment, so therefore
gawk can't get to them.

Arnold

> Date: Mon, 11 Dec 2006 13:54:32 +0100
> From: address@hidden
> Subject: Possible bug with shell arrays
> To: address@hidden
>
> 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]