There is already a working answer, sub-optimal though. Breaking out of a for loop seems unnecessarily complicated. You can create an array without a loop. In the following example we set anew the array of positional parameters; we do it in a subshell, so the main shell is not affected.
(shopt -s failglob # not portableset -- /path/to/pi-hole-srv-teleporter_* && echo mv -- "$1" /backup/teleporter.tar.gz)The script as-is is a no-op. Remove the echo to "arm" it.
Notes:
shopt -s failglobwill make the expansion of*fail if there is no match, thenmvwill not be attempted at all. Withoutfailgloband without a match the pattern would stay verbatim and it would get tomvas such. In our case it would not be so bad (mvwould just fail), but in general it's often better to detect the situation early.- The expansion of
*sorts the matching pathnames,setstores them in that order as positional parameters. In our code we use the first one:$1. You can easily get the last one:${!#}. The filenames in question are designed well, they will be sorted by the embedded timestamp. All this means you can pick the oldest or the newest file easily.