The array built-in prints or modifies arrays.

Syntax

  • array

  • array name [value…]

  • array -d name [index…]

  • array -i name index [value…]

  • array -s name index value

Description

When executed without any option or operands, the built-in prints all array definitions to the standard output in a form that can be parsed as commands.

When executed with name and values (but without an option), the built-in sets the values as the values of the array named name.

With the -d (--delete) option, the built-in removes the indexth values of the array named name. The number of values in the array will be decreased by the number of the indexes specified. If the indexth value does not exist, it is silently ignored.

With the -i (--insert) option, the built-in inserts values into the array named name. The number of values in the array will be increased by the number of the values specified. The values are inserted between the indexth and next values. If index is zero, the values are inserted before the first value. If index is larger than the number of values in the array, the values are appended after the last element.

With the -s (--set) option, the built-in sets value as the indexth value of the array named name. The array must have at least index values.

Options

-d
--delete

Delete array values.

-i
--insert

Insert array values.

-s
--set

Set an array value.

Operands

name

The name of an array to operate on.

index

The index to an array element. The first element has the index of 1.

value

A string to which the array element is set.

Exit status

The exit status of the array built-in is zero unless there is any error.

Notes

The array built-in is not defined in the POSIX standard.

The command array name value is equivalent to the assignment name=(value…).