[英]Shell script not recognising declared variables
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). 真的没有什么复杂的...我有一个Django应用程序,告诉用户输入用户名($ 1)和密码($ 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.
当我使用pkitool并为2个变量KEY_NAME和KEY_CA提供内容时,它可以工作...当我在网站上输入用户名和密码时,脚本甚至将变量的内容保存并保存在/ static中。 I can even execute the script itself in my shell when I pass 2 variables.... It looks like this then:
当我传递2个变量时,我什至可以在外壳中执行脚本本身。
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中,你们能告诉我这怎么可能吗?
You need to export your variables to have them picked up by sub-processes: 您需要导出变量以使它们被子流程拾取:
export KEY_NAME=$1
export KEY_CN=$2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.