Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring arrays in ZSH

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"
)
like image 952
alex-phillips Avatar asked May 15 '15 22:05

alex-phillips


1 Answers

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).

like image 94
Etan Reisner Avatar answered Oct 19 '22 10:10

Etan Reisner