Declaring Arrays in ZSH

I am having trouble converting a shell script to zsh. I have the following array, but it throws an error unknown file attribute: \n. (I will convert the dotfiles repository to my zsh)

declare -r -a FILES_TO_SOURCE=(
    "bash_aliases"
    "bash_exports"
    "bash_functions"
    "bash_options"
    "bash_prompt"
    "bash.local"
)
+4
source share
1 answer

From man zshbuiltins, when writing to typeset(of which declareis a synonym):

For each name = value assignment, the parameter value is set to a value. Note that arrays cannot currently 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

, , , (, bash -ism , ).

+3

All Articles