I have two independently running scripts. first one lets say script A calculates some values. And i want to echo these values from other script called B. These scripts will not call each other. I have used export keyword but didn't work. How can i do this?
相关问题
- How to get the return code of a shell script in lu
- JQ: Select when attribute value exists in a bash a
- Invoking Mirth Connect CLI with Powershell script
- Emacs shell: save commit message
- bash print whole line after splitting line with if
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- In IntelliJ IDEA, how can I create a key binding t
- Check if directory exists on remote machine with s
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- Is there a non-java, cross platform way to launch
- Reverse four length of letters with sed in unix
- Launch interactive SSH bash session from PHP
Of course you can also just read a single line when you want it.
In bash there are coprocs, which also might be what you want. Random example from this page
ksh has a similar feature, apparently
You may echo values to files, then the other script may read them. If you want to use it as a parameter for something, use reverse aposthrophe:
Be careful, if the two scripts are running at the same time, concurrency problems may occur, which can cause rarely appearing, mystic-looking errors.
Can't you read a third file, let's say settings.sh with the common exported variables?
and in both A and B
source common.sh
to load those values.Note that the export may not be required in that case.
Actually all your need is
source
you can skip theexport
prefix.My use-case was an environment specific settings file, example:
Within main_script.sh
Within config_vars.sh
If I understood the requirement then can't both scripts be simply executed in same sub shell, independently but without calling each other or without any need of an external file or pipe like this:
Let's say this is your script1.sh
And here us your script2.sh
Just call them in same sub-shell like this
OUTPUT:
Think of each script as a function: function A calculates some value and returns it. It does not know who will call it. Function B takes in some value and echo it. It does not care who produced that value. So, script A is:
and script B is:
Make them executable:
Now, we can glue them together on the command line:
Semantically, b.sh did not call a.sh. You called a.sh and passed its result to b.sh.