0

I am having some issues declaring an array in Bash.

I am trying to use declare -A props

But it gives me an error that states:

  declare -A: invalid option           
  declare: usage: declare [-afFirtx] [-p] [name[=value]] ...]

Any help would be greatly appreciated as the array is currently 0.

I am trying to create an array that stores a key and a value.

4
  • declare is a bash built-in. Are you using ksh or bash? Commented Jan 14, 2014 at 15:59
  • Why are you using -A ?? Commented Jan 14, 2014 at 15:59
  • are you by any chance using MacOS? Commented Jan 14, 2014 at 16:01
  • I am trying to create an array that stores keys and values using bash v3.00.16 Commented Jan 14, 2014 at 16:02

1 Answer 1

9

Associative arrays are declared using declare -A. Indexed arrays are declared using declare -a.

If you need the former, check your version of bash bash --version since they were introduced in bash 4.0.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.