Here’s a quick one… all AS, no shell (not a shell scripter)…
set nameExtension to "jpg" -- Change this as needed
set fileList to {} -- Set up an empty list to populate
tell application "Finder" to set tempFileList to ((name of every file of folder "AI Math Scripts" of desktop) whose name extension is nameExtension) -- Change the "of folder "AI Math Scripts" of desktop" by droplet, selection, choose folder, whatever.
repeat with thisFileName in tempFileList
set fileList to fileList & ((characters 1 through -((count of nameExtension) + 2) of thisFileName) as string) -- Subtract 2 to get beyond the dot prefix.
end repeat
choose folder
do shell script "/usr/bin/find " & quoted form of POSIX path of result & " -name '*.txt' -exec /usr/bin/basename {} \\; | /usr/bin/sed s/.txt$//g"
return paragraphs of result