I am very new to bash scripting but am having trouble accessing an array. (or what I believe to be an array) I am using a file glob to get the contents of an array.
I simply want to print each file and then allow the user to pick one based on its index. However I am noticing that everything is stored in the first element of the array. What am I missing? Is file globbing not the best idea here for what I want?
files=templates/*.tex
fnum=0
for file in $files
do
echo $fnum : $file
# bash expression is ((expression)) $(( expression )) expects a command
(( fnum++ ))
done
read -p "Which file would you like to include: " answer
if [ $answer -ge 0 ] && [ $answer -lt $fnum ]
then
echo ${$files[0]}
else
echo bad range...
exit 1
fi