Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 awk。我想模块化我的代码,我想知道在函数中声明的变量是局部变量还是全局变量。例如
main script update() function update() { array[1]="hi" }
我想知道函数内部声明的数组是局部的还是全局的..如果不是局部的,那么..awk中局部变量的概念是什么。
它们是全球性的:
awk 'function update() { array[1]="hi" } BEGIN { update(); print array[1];}' hi
要使其成为本地化,您需要一个小技巧,将其作为参数传递:
awk 'function update(array) { array[1]="hi" } BEGIN { update(); print array[1];}'