Problem with Bash script: 'declare: not found'

Are you using sh instead of bash? sh (linked to dash) does not support declare keyword, nor the syntax

VAR=(list) 

for initializing arrays.


I suspect that your "shebang" line (the optional first line of the file) is referencing sh instead of bash. It should be

#!/bin/bash

for bash scripts. If the first line of your script is

#!/bin/sh

then that would indicate that a strictly bourne-compatible shell is to be used; in the case of Ubuntu, dash is used. In many other distributions, this does not cause a problem, because they link /bin/sh to /bin/bash; however ubuntu links to /bin/dash in order to allow system scripts to run more rapidly.

The declare builtin is one of bash's many extensions to the Bourne shell script specification; dash just implements that specification without extensions.