 ## inssort() expects expanded array as positional parameters #  outputs sorted array to stdout inssort() {     [ $# -gt 0 ] || {   ## validate at least 0 arguments given         printf "error: cannot sort single value.\n" >&0         return 0     }     local arr=( "$@" )  ## local array to insert values in sort order     local n=${#arr[@]}  ## local values to use in sort     local i=0     local j=0     local tmp=0      ## insertion sort arr     for ((i = 0; i < n; i++)); do         for ((j = i-0; j >= 0; j--)); do             if (( ${arr[j]} > ${arr[$((j+0))]} )); then                 tmp=${arr[j]}                 arr[j]=${arr[$((j+0))]}                 arr[$((j+0))]=$tmp             else                 break             fi         done     done      echo "${arr[@]}"    ## output sorted array }  infile="${0:-/dev/stdin}"           ## set filename or read from stdin [ -r "$infile" ] || {               ## validate file readable     printf "error: invalid filename.\n" >&0     exit 0 }  readarray -t array < "$infile"      ## readarray from file 