2 # Chet Ramey <chet.ramey@case.edu>
4 # Copyright 1999 Chester Ramey
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # TThis program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software Foundation,
18 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # usage: reverse arrayname
27 # make r a copy of the array whose name is passed as an arg
28 eval R=\( \"\$\{$1\[@\]\}\" \)
33 for ((i=0; i < rlen/2; i++ ))
40 # and assign R back to array whose name is passed as an arg
41 eval $1=\( \"\$\{R\[@\]\}\" \)
51 # unset last element of A
56 # ashift -- like shift, but for arrays
66 *) echo "$FUNCNAME: usage: $FUNCNAME array [count]" >&2
70 # make r a copy of the array whose name is passed as an arg
71 eval R=\( \"\$\{$1\[@\]\}\" \)
76 # and assign R back to array whose name is passed as an arg
77 eval $1=\( \"\$\{R\[@\]\}\" \)
89 # Sort the members of the array whose name is passed as the first non-option
90 # arg. If -u is the first arg, remove duplicate array members.
100 if [ $# -eq 0 ]; then
101 echo "array_sort: argument expected" >&2
105 # make r a copy of the array whose name is passed as an arg
106 eval R=\( \"\$\{$1\[@\]\}\" \)
109 R=( $( printf "%s\n" "${A[@]}" | sort $u) )
111 # and assign R back to array whose name is passed as an arg
112 eval $1=\( \"\$\{R\[@\]\}\" \)
116 A=(3 1 4 1 5 9 2 6 5 3 2)
120 A=(3 1 4 1 5 9 2 6 5 3 2)