English 中文(简体)
2份说明 A和B.B. 有一些变数,可在A.How中加以使用,而A.How则应当做到。
原标题:2 scripts A and B.Script B has some variables that are to be used in A.How should i be going about it

我有两处文字A和B。 文字B有一些变数将在A.Also使用,我不得不通过文字A.How将文字B称作文字。

问题回答

如同你一样,这种声音有组合信息,可以从A或B中读取,如果是简单的组合信息,则应当在第三卷C中加以具体说明,而C则使用<代码>从A和B两种来源。 /C机制。

如果你试图从A中打出B,在B号电话中设定一个变量,然后在A读到这一数值,那么如果你重新使用标准<代码>/B,那么,在B号援引中确定的所有变量都不会被复制到A的环境。

两种文字之间交流变量的最明智方式是把A需要使用的变数输入临时档案,然后从A到B结束其运行后的来源。 更为复杂的方法涉及B把变数归入A类评价的电子阀载体。 B部分

#!/bin/bash -p
echo var=22

and then in A I do:

output=$(./B)
eval $output
echo $var

我将获得产出<代码>22<>。 这样做是正确的,只应依赖在文字之间转让的简短变量清单。

获取文字以分享变量的真正途径是使其仅包含功能,并具有在A和B中援引功能的主字母,例如:

#!/bin/bash -p

. ./A
. ./B

do_a_stuff
echo $shared_variable
do_b_stuff
echo $shared_variable

如果在A中存在以B中的代码为准的法典,那么,你最后拥有一个在其中共享的单一名称空间,这样你就可以在B中从A和A从B处援引职能(你认为这违反了功能等级,被认为是不好的编码)。

Marge two scripts toogether? Then you will have one list of varibles and all the functions will be in one place. If those two scripts are doing some very diffrent things then try to make them independent.

提 出

 # cat B
 #!/bin/bash
 echo "Date is: `date`"

 # cat A
 #!/bin/bash
 echo "You are login as: `whoami`"
 echo "`/bin/sh ./B`" # exact path for the script file

产出:

  # ./A
  You are login as: root
  Date is: Thu Oct 17 02:56:36 EDT 2013




相关问题
Portable way to get file size (in bytes) in the shell

On Linux, I use stat --format="%s" FILE, but the Solaris machine I have access to doesn t have the stat command. What should I use then? I m writing Bash scripts and can t really install any ...

Unix: fast remove directory for cleaning up daily builds

Is there a faster way to remove a directory then simply submitting rm -r -f *directory* ? I am asking this because our daily cross-platform builds are really huge (e.g. 4GB per build). So the ...

Startup time in Solaris server using shell script

How to find the start up time of a Solaris 5.1 server using a shell script,need to know how much time it took to be on running state?I need to know how much time it took to come to running mode from ...

Ruby 1.8.6 BigDecimal.to_f always returns 0,0 on Solaris

I have come across a very weird error. I m on Solaris 10, using Ruby Enterprise Edition (ruby 1.8.6 (2008-08-08 patchlevel 286) [i386-solaris2.10]) with Rails 2.3.4. I have a very weird error. In irb: ...

Where to set JDK to be used for SunOne server?

Where to set the JDK to be used by the SunOne server on Solaris? Is it all configured via an environment variable like JDK_HOME or JAVA_HOME, or is there a config file for the SunOne server somewhere ...

热门标签