ormaaj 1674157677 learn # bash -O extglob -c 'enable -f asort{,}; touch file_{7..13}.pdf; unset -v a b; typeset -A a; for x in file_+([[:digit:]]).pdf; do [[ -f $x && $x =~ ^[^[:digit:]]*([[:digit:]]+).* ]] && a+=([${BASH_REMATCH[1]}]=$x); done; typeset -a b=("${!a[@]}"); asort -n b; for x in "${!b[@]}"; do printf "%s${b[x+1]+ }" "${a[${b[x]}]}"; done; echo' # Numeric sort files matching a pattern by part of the file's name using bash's asort ormaaj 1674159058 forget ormaaj 1674159158 learn # bash -O extglob -c 'if [[ -v KSH_VERSION ]]; then typeset -n BASH_REMATCH=.sh.match; else enable -f asort{,}; fi; touch file_{7..13}.pdf; unset -v a b; typeset -A a; for x in file_+([[:digit:]]).pdf; do [[ -f $x && $x =~ ^[^[:digit:]]*([[:digit:]]+).* ]] && a+=([${BASH_REMATCH[1]}]=$x); done; typeset -a b=("${!a[@]}"); ${BASH_VERSION+\:} set -sK :n -A b; ${KSH_VERSION+\:} asort -n b; for x in "${!b[@]}"; do printf "%s${b[x+1]+ }"