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
精彩评论