I have a problem with my a bash script. What I do is assign variables like this.
for ((i=START;i<=END;i++)
declare var$i=$(something)
done
And it works, but now I have a problem with finnish characters like å, ä, ö. What declare says is something like this
bash:declare 'wörd' not a valid identifier
Though it works fine if I do it like this
declare var2=$(sömething)
I can convert the characters with sed but it's better to have them like always, so this is a last resort solution. So I would like to know how can I assign variables like
var$i
with the finnish characters. The wörd word is part of the output of my command 'something'. When there are two words or more only the word(s) that contain the character ö , ä and so on are not assigned to the variable, so if the output of the command was "something wörd" then the only thing that is being shown with echo is something.
$i
, and why do you want to do this? – Sterilizewörd
come in? – Sterilizebash
identifiers are ASCII only (a-z, A-Z, 0-9, _). A barewörd=1
(withoutdeclare
) is interpreted as a command, not an assignment statement, due to the non-ASCII character. It could deviate from the POSIX spec, as described in the link provided by Cyrus, but it doesn't. – Britteny