开发者

How to pass values from child shell to parent shell

开发者 https://www.devze.com 2023-01-04 12:48 出处:网络
How to pass values from child she开发者_如何学Pythonll to parent shell in shell programming?See my answers here and here for discussions and demonstrations of variable scoping in the shell. There aren

How to pass values from child she开发者_如何学Pythonll to parent shell in shell programming?


See my answers here and here for discussions and demonstrations of variable scoping in the shell. There aren't any global variables.

The usual methods for passing values include printing the value or using a temporary file.

Example child and parent:

#!/bin/sh
# child.sh
a=4321
echo $a

and

#!/bin/sh
# parent.sh
val=$(child.sh)
echo $val


This is impossible. The best that can be done is for the child to print the desired assignments, and for the parent to exec them.


If you want to return an integer use the exit status to do the same.

exit x # x can be any integer
0

精彩评论

暂无评论...
验证码 换一张
取 消