Zsh Variable Assignment – Troubleshooting Guide

zsh

I have this line in a function I'm adapting from a bash function into zsh function:

local info=( $(command df -P $fs | awk 'END{ print $2,$3,$5 }') )

Whenever I call it in the func I get this:

mydf:9: bad pattern: info=( 712687280

But when I call it from the shell I get the expected answer:

$ info=($(command df -P $fs | awk 'END{ print $2,$3,$5 }'))
$ echo $info                                                                                      
712687280 166242288 25%

I am 2 days into zsh so I'm a little ignorant as to what's causing the problem.

Best Answer

Put the assignment on a separate line from the local definition:

local info
info=( $(command df -P $fs | awk 'END{ print $2,$3,$5 }') )
Related Question