13

I'm having trouble converting a shell script to zsh. I have the following array defined, but it is throwing the error unknown file attribute: \n. (I'm converting a dotfiles repo to my zsh)

declare -r -a FILES_TO_SOURCE=(
    "bash_aliases"
    "bash_exports"
    "bash_functions"
    "bash_options"
    "bash_prompt"
    "bash.local"
)

1 Answer 1

12

From man zshbuiltins, under the entry for typeset (of which declare is a synonym):

For each name=value assignment, the parameter name is set to value. Note that arrays currently cannot be assigned in typeset expressions, only scalars and integers.

Try this instead:

declare -a FILES_TO_SOURCE
FILES_TO_SOURCE=(
    "bash_aliases"
    "bash_exports"
    "bash_functions"
    "bash_options"
    "bash_prompt"
    "bash.local"
)
declare -r FILES_TO_SOURCE

That being said that list of files is going to have to change here too most likely for compatibility (assuming you've used bash-isms in those files which seems likely).

Not the answer you're looking for? Browse other questions tagged or ask your own question.