父脚本 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"
子脚本 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"
结论
1 本地变量无法传递到子进程
2 环境变量对所有的子进程都有效
3 无论本地变量还是环境变量都无法向父进程传递参数