In the bash shell, set
is used to control the numbered variables like $0
, $1
, etc. and shell option settings.
For other shell variables you just set them. Like this:
character=(a b c d e f g)echo "${character[1]}"
Although I suppose that you can use declare
or local
as necessary.
You need to use the bracket characters like ${variable}
because that works for all Bourne compatible shells and won't result in weird results even if the shell does not understand arrays. It'll just come out blank.
I am not sure what you expect with your third line, but [2-5]
will not create an array slice of 2 through 5. It will evaluate to -3
which will start at the back of the array and count back -3
to produce e
.