简体   繁体   English

如何在 Linux 中将变量从一个 ksh 脚本传递到另一个 ksh 脚本

[英]How to pass the variables from one ksh script to another ksh script in Linux

I have below 2 scripts我有以下 2 个脚本

Script1.ksh

      Some  Code

      Var1 = value1

      Var2 = value2

      Var3 = value3

Script2.ksh

     Ksh path/Script1.ksh

     #Trying to use Var1, Var2, Var3 in below code.
     
      Some Code

I want to use these Var1,Var2,Var3 values in Script2.ksh .我想在Script2.ksh使用这些Var1,Var2,Var3值。 I searched the web and tried export option and it didn't work out.我在网上搜索并尝试导出选项,但没有成功。 Please help me in this issue.请帮助我解决这个问题。

In script2, when you do在 script2 中,当你做

ksh path/to/script1.ksh

that launches a new ksh process, executes the script (setting the variables) and then the process exits, taking the variables with it.启动一个新的 ksh 进程,执行脚本(设置变量),然后进程退出,并带走变量。

You need to use the .您需要使用. command (or its alias source ) to read script1 in the current process .命令(或其别名source在当前进程中读取 script1 。

source path/to/script1.ksh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM