为什么即使重新分配,该命令也不会从文件中获取输入?

时间:2018-11-22 16:24:07

标签: bash shell input terminal io-redirection

执行时,cisco anyconnect VPN客户端从终端获取VPN IP,密码和其他一些输入。但是,我没有每次都键入它,而是写下了文件中的值,然后尝试将文件重定向到vpn client命令中。

/opt/cisco/anyconnect/bin/vpn < vpndetails.txt

但是,该命令似乎忽略了文件重定向并仍然提示输入。这怎么可能?代码是否从其他文件描述符(不是0)读取并仍从终端读取?有可能吗?

注意:我知道将密码存储在文件中不是一个好习惯,但是现在我不在乎。

1 个答案:

答案 0 :(得分:1)

“是否可能”问题的答案为“是”。

anyconnect vpn的代码可能读为/ dev / tty,如Chepner e.a的评论所述。作为一个有趣的练习,请尝试以下脚本:

#! /bin/sh 

read -p "STDIN> " a
read -p "TERMINAL> " b  < /dev/tty
read -p "STDIN> " c

echo "Read $a and $c from stdio and $b from the terminal"

,例如ls / | bash this_script.sh

但是,如果您希望使用不带密码的Cisco Autoconnect,则应该研究“始终处于受信任的网络状态”检测功能和用户证书。

写到/dev/tty希望脚本将其拾取不起作用:

ljm@verlaine[tmp]$ ls | bash test.sh &
[3] 10558
ljm@verlaine[tmp]$ echo 'plop' > /dev/tty
plop

[3]+  Stopped                 ls | bash test.sh
ljm@verlaine[tmp]$ fg
ls | bash test.sh
(a loose enter is given)
Read a_file and b_file from stdio and  from the terminal