C语言-指针2
2026/7/29 5:06:10
isortisort函数用于对命令行参数进行排序。以下是该函数的代码:
isort() { local -a a a=( "$1" ) ## put first argument in array for initial comparison shift ## remove first argument for e ## for each of the remaining arguments… do if [ "$e" \< "${a[0]}" ] ## does it precede the first element? then a=( "$e" "${a[@]}" ) ## if yes, put it first elif [ "$e" \> "${a[${#a[@]}-1]}" ] ## if no, does it go at the end? then a=( "${a[@]}" "$e" ) ## if yes, put it at the end else ## otherwise, n=0 while [ "${a[$n]}" \< "