Linux 脚本从命令行正确运行,但未嵌入到其他脚本中

Linux 脚本从命令行正确运行,但未嵌入到其他脚本中,linux,bash,Linux,Bash,从命令行使用encpass时:没问题 #!/bin/sh label=$1 . ./encpass.sh password=$(get_secret $label) echo "passw $password [dbadmin@luechdb61 scripts]$ ./secret.sh dbllud1 passw Vxxxxxxxxxxxxxxxxxxxxxxxx [dbadmin@luechdb61 scripts]$ ./secret.sh dbllud2 passw Tyyyyy

从命令行使用encpass时:没问题

#!/bin/sh
label=$1
. ./encpass.sh
password=$(get_secret  $label)
echo "passw $password
[dbadmin@luechdb61 scripts]$ ./secret.sh  dbllud1
passw Vxxxxxxxxxxxxxxxxxxxxxxxx
[dbadmin@luechdb61 scripts]$ ./secret.sh  dbllud2
passw Tyyyyyyyyyyyyyyyyyyyyyyyyy
已正确检索密码 现在我从另一个脚本调用它

在本例中:我也回显了输入,并且是正确的 但是get_secret无法识别这一点,并且希望创建一个新条目,尽管条目显示正确

[dbadmin@luechdb61 scripts]$ ./db2Deploy.sh -s scr.sql -m deploy.lst -e d
handling script_name scr.sql for server_name : luechdb61 dbname : IEEINT
xdbllud1x   <--- echo from script x${usr_name}x
Enter dbllud1:
stty: standard input: Inappropriate ioctl for device
stty: standard input: Inappropriate ioctl for device
[dbadmin@luechdb61脚本]$./db2Deploy.sh-s scr.sql-m deploy.lst-e d
处理服务器的脚本\u name scr.sql\u name:luechdb61 dbname:IEEINT

xdbllud1x执行命令时,该命令的标准输入流取自键盘,标准输出和错误流进入终端屏幕

echo "Hello world!"
使用此命令,“Hello world!”将显示在屏幕上

但是,当您在
$(…)
中执行相同的命令时,标准输入和输出流位于子shell中,不会干扰连接到键盘和屏幕的当前shell。在这种情况下,标准输出被发送到变量
usr\u name

usr_name=$(echo "Hello world!")
使用此命令,您在屏幕上看不到任何内容,但如果要在屏幕上显示此消息,则需要运行:

echo "$usr_name"
绕过此问题的一种可能方法是将输出发送到名为
/dev/tty
的特殊文件。因此,发布:

usr_name=$(echo "Hello world!" > /dev/tty)
将保留变量
$usr\u name
为空,并向终端发送“Hello world!”,即使从子shell执行。也可以从终端直接从子shell读取密码。尝试:

$(get_secret ${usr_name} < /dev/tty)
$(获取机密${usr\u name}

就我所猜测的代码而言,由于您没有提供函数
get_secret()
或命令
get_secret

的代码,因此建议今后:始终提供完整的工作(简化)代码,而不仅仅是备用代码片段。如何创建感谢所有更新。encpass.sh的所有者建议在调用他的encpass.sh之前添加set。这就纠正了问题。向你问好,盖伊
$(get_secret ${usr_name} < /dev/tty)