0

The following line in a bash script:

declare -A aa

results in the following error:

./test: line 57: declare: -A: invalid option

Which I would have expected if I were running pre v4, but I'm on OS X Sierra 10.12.6 running GNU Bash 4.4.12.

codeforester
  • 39,467
  • 16
  • 112
  • 140
Jalakoo
  • 3,523
  • 2
  • 21
  • 20
  • 1
    You're clearly *not* running bash 4.4.12. – Charles Duffy Oct 03 '17 at 20:55
  • Are you sure you're running that Bash? What's your shebang line (the first line in the script)? Run that path with `--version`. – Benjamin W. Oct 03 '17 at 20:55
  • Note that OS X Sierra ships bash 3.2 (because Apple refuses to accept GPLv3 licensing). If you're using `/bin/bash`, then you have the one Apple shipped you, not what MacPorts or Homebrew installed. – Charles Duffy Oct 03 '17 at 20:55
  • 1
    I bet it's a `#!/bin/bash` vs `#!/usr/bin/env bash` problem. – Benjamin W. Oct 03 '17 at 20:55
  • Can you show us what `test`'s contents look like (mostly the shebang)? – wkl Oct 03 '17 at 20:55
  • Put `echo "$BASH_VERSION"` in your script, next to the failing line, so we get the actual value at runtime. – Charles Duffy Oct 03 '17 at 20:56
  • (...so, you can't trust `bash --version` to match `/bin/bash --version`). – Charles Duffy Oct 03 '17 at 20:56
  • And, ahem, my I point to my answer in the duplicate, which seems to address this exact scenario. – Benjamin W. Oct 03 '17 at 20:59
  • Thanks everyone, yes, ends up my question is a duplicate to the one posted up to. Strangely it didn't show up in my search (and still doesn't even when I put the exact title in). Regardless, I did need to change `#!/bin/bash` to `#!/usr/bin/env bash`. Thanks @BenjaminW. – Jalakoo Oct 03 '17 at 21:16
  • @CharlesDuffy: Output I get was: `4.4.12(1)-release` – Jalakoo Oct 03 '17 at 21:20
  • From `bash --version`: `GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin16.3.0)` – Jalakoo Oct 03 '17 at 21:20
  • @Jalakoo, not from `bash --version`, not from your interactive shell, but from `echo "$BASH_VERSION"` **when it's actually in your script, right next to the `declare -A` that fails**? (I specified "next to the failing line" in my original comment for a reason). – Charles Duffy Oct 03 '17 at 21:24
  • @CharlesDuffy Yes, that was the output when `echo "$BASH_VERSION"` was placed in the script, not from terminal's interactive shell. – Jalakoo Oct 03 '17 at 21:37
  • That output would make sense *if* you'd already fixed the shebang. On MacOS 10.12.6, `/bin/bash -c 'echo "$BASH_VERSION"'` emits `3.2.57(1)-release`. – Charles Duffy Oct 03 '17 at 22:28

0 Answers0