0

I am trying to do this:

declare -a ip_array=( [127.0.0.1]=127.1.1.1 [127.1.1.1]=127.0.0.1 )

However bash complains as it thinks the decimals are operators:

bash: 127.0.0.1: syntax error: invalid arithmetic operator (error token is "127.0.0.1")

I tried using single and double quotes but it seems to evaluate arithmetically every time.

EDIT: I did not notice that there is a difference between lowercase -a and uppercase -A options when declaring an array.

echodrome
  • 141
  • 1
  • 11

1 Answers1

1

[- +] a declares NAMEs as an indexed array (deleting with + acceptable syntax, but results in an error message)

[- +] A declares NAMEs as an associative array

Try this:

declare -A AR=( [127.0.0.1]=127.1.1.1 [127.1.1.1]=127.0.0.1 ); echo ${AR[@]};
soft87
  • 482
  • 2
  • 16