#Bash 的 declare 命令
local NAME[=VALUE]...
功能
定义局部变量。
类型
Bash 内置命令。
参数
NAME- 变量名VALUE- 变量的值
#示例
function demo()
{
local N=10
echo $N
}
N=hello
echo $N
demo # 调用函数
echo $N # 外部的 N 没有改变
运行结果:
hello
10
hello
#相关命令
| 命令 | 说明 |
|---|---|
| declare | 声明变量并设置属性 |
#手册
local: local [option] name[=value] ...
Define local variables.
Create a local variable called NAME, and give it VALUE. OPTION can
be any option accepted by `declare'.
Local variables can only be used within a function; they are visible
only to the function where they are defined and its children.
Exit Status:
Returns success unless an invalid option is supplied, a variable
assignment error occurs, or the shell is not executing a function.