Shell脚本无法识别声明的变量

时间:2021-09-12 23:36:22

I got a shell script with 4 variables .So far so good:

我有一个包含4个变量的shell脚本。太好了:

#!/bin/bash

echo keygeneration $1 $2 >> /tmp/logfile
touch /home/ubuntu/newproject/static/$1

KEY_NAME=$1
KEY_CN=$1

sh pkitool

there is really nothing complicated about it... I got a Django app which tells the user to type in Username ($1) and Password ($2). when I use the pkitool and give the 2 variables KEY_NAME and KEY_CA a content, it works... when I type in the Username and Password on the website the script even saves the content of the variable and saves it in /static. I can even execute the script itself in my shell when I pass 2 variables.... It looks like this then:

它真的没有什么复杂的...我有一个Django应用程序告诉用户输入用户名($ 1)和密码($ 2)。当我使用pkitool并将2个变量KEY_NAME和KEY_CA作为内容时,它可以工作......当我在网站上输入用户名和密码时,脚本甚至会保存变量的内容并将其保存在/ static中。当我传递2个变量时,我甚至可以在我的shell中执行脚本....它看起来像这样:

sh keygen.sh FooUsername BarPassword

the only thing that does not work is, when I type in Username and Password in the app, it won't execute the pkitool correctly and the 2 variables KEY_NAME=$1 and KEY_CN=$1 aren't declared.. but that is totally weird because it does save the variable $1 though in static Oo can you guys tell me how this could come ?

唯一不起作用的是,当我在应用程序中输入用户名和密码时,它将无法正确执行pkitool,并且未声明2个变量KEY_NAME = $ 1和KEY_CN = $ 1 ..但这完全是奇怪的因为它确实保存变量$ 1虽然在静态Oo你们可以告诉我这是怎么来的吗?

1 个解决方案

#1


1  

You need to export your variables to have them picked up by sub-processes:

您需要导出变量以通过子流程获取它们:

export KEY_NAME=$1
export KEY_CN=$2

#1


1  

You need to export your variables to have them picked up by sub-processes:

您需要导出变量以通过子流程获取它们:

export KEY_NAME=$1
export KEY_CN=$2