bash simply does not allow identifiers to use characters other than AZ, az, 0-9, and _. However, the error you described is only a side effect of this limitation. declare is a command that takes a string argument that looks like an assignment operator, but the semantics are slightly different. Consider this command:
foo () { echo "something wörd" }
In the assignment operator, the right-hand side does not undergo word splitting, so you do not need to specify a command replacement. The following works great:
$ word3=$(foo) $ echo "$word" something wörd
With declare , however, command substitution undergoes word splitting, so when you write
$ i=3 $ declare word$i=$(foo)
it is equivalent to a team
$ declare word3=something wörd
which passes two names for declare to create, word3 (which gets the value) and wörd (this is an invalid name). declare word3="something wörd" will work fine; splitting of the shell word is already performed by the time declare receives an argument.
With declare , then you need to specify command substitution (or the entire string) so that all output is treated as the value for the new variable.
$ i=3 $ declare "word$i=$(foo)" $ echo "$word3" something wörd
source share