[Top][All Lists]

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

Re: Selecting out of an array

From: Jon_R
Subject: Re: Selecting out of an array
Date: Wed, 27 Jan 2010 18:24:59 -0800 (PST)

It's not necessary to print the array, select will do that for you.
The way you're using select makes it only have access to one value
which is the last one in the array because the "for index" loop leaves
index pointing to the last array element. Also, don't use ls like this
- it's eyes-only.

Try this (or something similar):

if [ $# -eq 0 ]; then
        ARRAY=( quit /home/jonr/Download/videoDriver/video/* )  # file
globbing instead of ls
        select ITEM in "address@hidden" ; do                       #
using @ as the subscript
                if [[ $ITEM == "quit" ]]
                printf "%s\n" "$ITEM"                           # this
is where you'd process the selection
        echo "Nothing to see here"

The @ sign gives select access to the whole array.

Wow! That is exactly what I was trying to accomplish. I didn't want to have
to define every file with its own variable. Shoving everything into an array
and then being able to 'select' it out is so much easier.

I am having a difficult time because while I know what I want to do, I just
don't know how to ask the right question. :) So if my posts are long I am
just trying to give as much information as possible so I will be understood.

Thanks Dennis!!

View this message in context: 
Sent from the Gnu - Bash mailing list archive at Nabble.com.

reply via email to

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