关于Shell脚本变量传递
1 本地变量无法传递到子进程
2 环境变量对所有的子进程都有效
1 本地变量无法传递到子进程
2 环境变量对所有的子进程都有效
3 无论本地变量还是环境变量都无法向父进程传递参数
论坛上的一位达人给了个非常经典的例子,记在这里:
hadoop3@linux-240:~> cat father.sh
#!/bin/bash
# echo father pid
echo "Father Process ID is $$"
# define local env
localvar="Define a local variable."
echo "localvar=$localvar"
ENVVAR="Define a environment variable."
export ENVVAR
echo "ENVVAR=$ENVVAR"
$PWD/child.sh
echo "Retrun to father process: $$"
echo "localvar=$localvar"
echo "ENVVAR=$ENVVAR"
hadoop3@linux-240:~> cat child.sh
#!/bin/bash
echo "Child Process ID is $$"
echo "My Father Process ID is $PPID"
echo "localvar=$localvar"
echo "ENVVAR=$ENVVAR"
localvar="Redefine this local variable."
ENVVAR="Redefine this environment variable."
echo "localvar=$localvar"
echo "ENVVAR=$ENVVAR"
hadoop3@linux-240:~>