Hitachi

JP1 Version 11 JP1/Advanced Shell Description, User's Guide, Reference, and Operator's Guide 


10.3.4 sortArray (sorts array data)

Syntax

sortArray  [-d element-number] [-n] [-r]  array-name-1 array-name-2

Description

This command sorts the value of the array specified for argument. Characters contained in the value are case-sensitive.

Arguments

-d element-number

This command sorts the value of two-dimensional array corresponding to the specified element number. To sort values of all two-dimensional array elements, specify "@" for the element number. If you specify "@", the values of elements in each array corresponding to the first element number of two-dimensional array are sorted. For example, if the two-dimensional array is 2 x 3, sort a value of elements among array[0][0], array[0][1] and array[0][2] and sort a value of elements among array[1][0], array[1][1] and array[1][2].

If you do not specify this option, interpret the array as one-dimensional array and sort the array.

-n

This command interprets the leading value character string as numerical values and sorts values.

-r

This command specifies sorting in descending order.

If you specify this option, the default is sorting in ascending order.

array-name-1

This command specifies the array names to be sorted.

array-name-2

This command specifies the name of array in which sorted data is stored.

Output to the standard output

None

Return codes

Return code

Meaning

0

Normal termination

Not less than 1

Termination with an error

Notes

Examples

set -A input Tokyo Yokohama Fukuoka Nagoya
sortArray input output
echo "${output[@]}"        # "Fukuoka Nagoya Tokyo Yokohama" is output.

set -A input Tokyo Yokohama Fukuoka Nagoya
sortArray -r input output
echo "${output[@]}"        # "Yokohama Tokyo Nagoya Fukuoka" is output.

set -A input -- -3 70 -50 8 100
sortArray -n input output
echo "${output[@]}"        # "-50 -3 8 70 100" is output.

set -D input { Osaka Fukuoka Nagoya } { Tokyo Yokohama Chiba }
sortArray -d 1 input output
echo "${output[0][@]}"     # "Osaka Fukuoka Nagoya" is output.
echo "${output[1][@]}"     # "Chiba Tokyo Yokohama" is output.

set -D input { Osaka Fukuoka Nagoya } { Tokyo Yokohama Chiba }
sortArray -d @ input output
echo "${output[0][@]}"     # "Fukuoka Nagoya Osaka" is output.
echo "${output[1][@]}"     # "Chiba Tokyo Yokohama" is output.