Here you go:
select date in dates=($(for i in backups/*.tar.bz2;do #Glob eliminates need to list all files
date=${i/Complete Backup /} #Remove "Complete Backup "
date=${date%%.*} #Remove ".tar.bz2"
date=${date/ /,} #Substitue , for space
echo $date #Echo the date for sed
done|sed -e 's/\([0-9]\+\)-\([0-9]\+\)-\([0-9]\+\)$/\1:\2:\3/'|sort -rr|xargs echo))
select date in ${dates[@]};do
echo "$date"
done
One more thing: if you're using this for a select loop, how are you going to tell the different dates apart when they're space-separated? I mean you use space to separate the date from the time as well so this might be a source of confusion.
Edit
- Added sorting of the dates from newest to oldest since your comments indicate that you need them sorted that way.
- Added code to separate date and time by a comma so that
selectcan tell a date and time pair from a new entry altogether. - Wrapped
Wrapped the whole in aStored the whole indates into an array which is then iterated over by aselectloopselectloop to avoid having to re-parse the dates for each re-run of the loop.