Script to select a file from a list

i m trying to write a script that will print all the txt files at /home/ directory
and will allow a selection of a file and then print the file name.

this is what i wrote so far:

echo "please select the file from the list "
list=$(ls -f *.txt  /home/)
array=( )
for machine in $list
do

at the end the output should be as so:

home/som# please select the file from the list
1.david.txt
2.vgersh99.txt
3.radoulov.txt
/home/som# 3
radoulov.txt
/home/som#
echo "Please select the file from the list"

files=$(ls *.txt)
i=1

for j in $files
do
echo "$i.$j"
file=$j
i=$(( i + 1 ))
done

echo "Enter number"
read input
echo "You select the file ${file[$input]}"
1 Like