Stuck with menu in select

hi i am new to bash scripting ..
i created a bunch of folders but only want the folder names with file1. so i go in and make an array to grab the folders the put in a file then i strip the directories so i just have the folder names i need then i would like to make the menu with a selection but how do i case the selections to be dynamic so if i have 7 or 3 file1. it will work as i would like to take the selected file name and then send it as a varible for later use

i have a file structure like this
folder1 has files1.1 files1.2 files1.3 testmyfile thefiletest other

here is my code:

    clear
    
    array=(/mytest/folder1/files1.*)
    printf "%s \n" "${array[@]}"  >testfile.txt

    fileList=$(</mytest/folder1/files1/testfile.txt )
    
    listarry=()
    for i in $fileList[@]
        do            
            if [[ "$i" == *"."* ]]; then
                splitList=$(echo $i | cut -d"/" -f4)
                if [[ ! "$listarry[@]" =~ "$splitList" ]]; then
                    listarry+=" $splitList"
                fi
            fi 
        done
echo "$listarry"

PS3="select number or Q to quit: "

COLUMNS=12 
select filename in $listarry; do
        if [-n "$filename" ]; then
            vim ${filename}
        fi
        break
    done
thanks

lamby22

You say that you have a bunch of directories several of which contain a file named file1 . And you say that you want to be able to give bash 's select a list of directories that contain a file named file1 . But you then go on to say that the directory /mytest/folder1 contains the six files: files1.1 , files1.2 , files1.3 , testmyfile , thefiletest , and other (none of which are named file1 ) and your code is only looking for files in the directory named /mytest/folder1 with names that start with files1. (including the s and the <period> and not looking for files in any other directory).

If you're looking for files named file1 in several directories, one might have expected you to use:

array=(/mytest/*/file1)

or (if the files you want are deeper in a file hierarchy):

array=( $(find /mytest -name file1) )

instead of:

array=(/mytest/folder1/files1.*)

Please clarify what you are really trying to do.

hi dan,
sorry i wasn't clear sounded good in my head.
i have a group of files in the directory mytest/folder1 inside that folder are multiple files
i would like to only pull out certain files( files1.* ) from folder and list them but the files sometime change i may pull out 3 one time or 7 the next depends on what i am selecting

example (take the files that have files1.* only out

mytest/folder1/ 
                     files1.1
                     files1.2 
                     files1.3 
                     testmyfile 
                     thefiletest
                     other

output this time would be this

1) files1.1
2) files1.2
3) files1.3

Sorry I seem to be a bit thick - I don't understand your usage of the term "folder" (bunch of) in your post#1. Should you be talking of one single directory /mytest/folder1 containing many files amongst which there are files1.1 , files1.2 , and files1.3 , what keeps you from trying

cd /mytest/folder1
select FN in $(ls files1*) exit; do echo $FN, $REPLY; done
1) files1.1
2) files1.2
3) files1.3
4) exit
#? 1
files1.1, 1
.
.
.

, and then, if done, cd back to the original working directory?