bug-bash
[Top][All Lists]
Advanced

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

Re: For loop prints two $values instead of one


From: Chris Down
Subject: Re: For loop prints two $values instead of one
Date: Tue, 7 Jan 2014 13:48:37 +0800
User-agent: Mutt/1.5.22 (2013-10-16)

Hello,

On 2014-01-07 00:45:42 +0200, DanielB wrote:
> I've a problem with bash array loop.
> 
> the following code instead of printing each value separately, joins two
> values and prints them as if they are one.
> 
> declare -a array=( 'sf052' 'to060' 'pw' 'qb099' 'pw22' 'wp039' 'wx12'
> 'wx11' )for subD in "${array[@]}"; do
>     echo $subDdone

Your formatting is messed up, please use a sane editor/mail server that
won't mangle output in future. :-)

I am assuming this should read:

    declare -a array=( 'sf052' 'to060' 'pw' 'qb099' 'pw22' 'wp039' 'wx12' 
'wx11' )

    for subD in "${array[@]}"; do
        echo $subD
    done

> output:
> 
> sf052
> to060
> pw
> qb099 pw22
> wp039 wx12
> wx11
> 
> "expected output":
> 
> sf052
> to060
> pw
> qb099
> pw22
> wp039
> wx12
> wx11

I get the expected output when running the code I just posted above, on
the same version of bash.

Attachment: pgpm2lDbqTSJy.pgp
Description: PGP signature


reply via email to

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