zsh: unknown file attribute

Marcel picture Marcel · May 14, 2016 · Viewed 23.6k times · Source

I have the following function in my .zshrc which, in theory, allows me to write a commit message without needing quotation marks.

cm(){
    git commit -m "$@"
}

When I run it (cm foo bar), I get the following error:

zsh: unknown file attribute

Does $@ mean the same thing in zsh as it does in bash?

Answer

Adam Lee picture Adam Lee · May 14, 2016

Accoring to this article, * and @ both contain an array of the positional parameters.

The parameters *, @ and argv are arrays containing all the positional parameters; thus $argv[n], etc., is equivalent to simply $n.

And...

A subscript of the form [*] or [@] evaluates to all elements of an array; there is no difference between the two except when they appear within double quotes. "$foo[*]" evaluates to "$foo[1] $foo[2] ...", whereas "$foo[@]" evaluates to "$foo[1]" "$foo[2]" ....