bash scope problem - Linux

This is a discussion on bash scope problem - Linux ; Hello, Can someone please tell me what I'm doing wrong or have set wrong? From a bash command line, if I type read -a array then type 1 2 3 I get an array that contains array[0]=1 array[1]=2 array[2]=3 All ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: bash scope problem

  1. bash scope problem

    Hello,

    Can someone please tell me what I'm doing wrong or have set wrong?

    From a bash command line, if I type

    read -a array

    then type
    1 2 3

    I get an array that contains
    array[0]=1
    array[1]=2
    array[2]=3

    All is good.

    But, if I type

    echo "1 2 3" | read -a array

    I don't have any array defined.

    It looks like this must be spawning some sort of shell or exec and the array
    is being defined locally in that context and then is not returned to my
    current shell.

    This problem exists even if I try using
    declare -a array
    and/or
    typeset -a array

    Call me an idiot for not knowing what must be a trivial problem but please
    let me know what I'm doing wrong! How can I do this and bring the array
    into the current shell?

    Thanks,
    Dave

  2. Re: bash scope problem

    Forgot to mention:

    bash --version
    GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu)
    Copyright (C) 2002 Free Software Foundation, Inc.

    Thanks,
    Dave

  3. Re: bash scope problem

    Nevermind, I RTFM'ed the BASH FAQ, found the answer at E4.

+ Reply to Thread