在zsh中执行test test.txt
(假设存在test.txt
时)。当test:local: not an identifier:
定义为:
test
错误
function test() { local test=$(gzip -c "$1" | wc -c); echo "$test" }
现在,我已将此范围缩小到使用local
关键字,因为在local
关键字被移除时不会引发任何错误:
function test() { test=$(gzip -c "$1" | wc -c); echo "$test" }
我感兴趣的是为什么只有当变量是作用域时才抛出错误,如果这是我在ZSH中如何确定变量的问题,我感兴趣的是调整变量范围的正确方法。