SSH远程命令未正常工作
问题描述:
我有一个名为test.sh
我的服务器上的脚本预期(问题读取):SSH远程命令未正常工作
#!/bin/bash
read -p "Select an option [1-4]: " option
echo "You have selected $option"
当我通过ssh手动运行它,我看到:
[email protected]:~$ ssh [email protected]
[email protected]'s password:
[...]
[email protected]:~# bash test.sh
Select an option [1-4]: 48
You have selected 48
当我运行它作为SSH远程命令,我看到:
[email protected]:~$ ssh [email protected] 'bash test.sh'
[email protected]'s password:
48
You have selected 48
我不满意这个输出,因为它是小姐ing Select an option [1-4]:
提示字符串和从我得到的原始脚本test.sh
包含很多像这样的交互式对话字符串,我需要它们。
我知道read
打印它的提示stderr
所以我试图用如果省略标准错误以下的情况下,命令启动脚本,但输出保持还是一样:
ssh [email protected] 'bash test.sh >&2'
ssh [email protected] 'bash test.sh' >&2
ssh [email protected] 'bash test.sh 2>&1'
ssh [email protected] 'bash test.sh' 2>&1
为什么发生这种情况和如何让SSH远程命令按预期工作?
UPD
我已经改变了test.sh
这样:
#!/bin/bash
echo Connected
read -p "Select an option [1-4]: " option
echo "You have selected $option"
但产出仍下落不明的提示字符串:
[email protected]:~$ ssh [email protected] 'bash test.sh'
[email protected]'s password:
Connected
66
You have selected 66
我已更新该问题。提示仍然丢失。 – user619271
如果您只想打印该行,则使用'echo'打印行,然后使用'read'读取值。它是一种解决方法。 –