zsh: unknown file attribute
Asked Answered
L

2

12

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?

Lelialelith answered 13/5, 2016 at 22:54 Comment(0)
A
9

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]" ....

Analyze answered 13/5, 2016 at 23:16 Comment(3)
That seems to work now with ${} instead of $. I wonder why zsh would implement this differently.Lelialelith
You mean that you substituted "$@" in your code with "${@}"?Analyze
No sorry that was confusing. I substituted "$@" with "${*}". I put the wrong thing in my comment because that's what I started with. I just switched $* to $@ when I was troubleshooting. As I understand it, $@ is like an array and $* is a space-separated string.Lelialelith
S
4

If you are also getting this similar error zsh: unknown file attribute: 1 while running a command then it may be due to character ( and )

For me I was trying to delete a git remote branch with name example-(123) it throws the above mentioned error, you can fix it by wrapping the branch name in single/double quotes e.g below

git push --delete origin "example-(123)"

Stockmon answered 20/6, 2023 at 7:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.