Current Path : /compat/linux/proc/68247/root/compat/linux/proc/68247/root/compat/linux/usr/share/doc/bash-3.2/functions/ |
FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64 |
Current File : //compat/linux/proc/68247/root/compat/linux/proc/68247/root/compat/linux/usr/share/doc/bash-3.2/functions/sort-pos-params |
# Sort the positional paramters. # Make sure the positional parameters are passed as arguments to the function. # If -u is the first arg, remove duplicate array members. sort_posparams() { local -a R local u case "$1" in -u) u=-u ; shift ;; esac # if you want the case of no positional parameters to return success, # remove the error message and return 0 if [ $# -eq 0 ]; then echo "$FUNCNAME: argument expected" >&2 return 1 fi # make R a copy of the positional parameters R=( "${@}" ) # sort R. R=( $( printf "%s\n" "${R[@]}" | sort $u) ) printf "%s\n" "${R[@]}" return 0 } # will print everything on separate lines set -- 3 1 4 1 5 9 2 6 5 3 2 sort_posparams "$@" # sets without preserving quoted parameters set -- $( sort_posparams "$@" ) echo "$@" echo $# # sets preserving quoted parameters, beware pos params with embedded newlines set -- 'a b' 'a c' 'x z' oifs=$IFS IFS=$'\n' set -- $( sort_posparams "$@" ) IFS="$oifs" echo "$@" echo $# sort_posparams