如何从shell脚本中的密码,而不回显 [英] How to get a password from a shell script without echoing
问题描述
我有自动化需要密码保护系统访问的过程的脚本。该系统是通过接受用户的密码作为参数的命令行程序访问。
I have a script that automates a process that needs access to a password protected system. The system is accessed via a command-line program that accepts the user password as an argument.
我想提示用户需要键入密码,并将其分配给一个shell变量,然后使用该变量来构建访问程序的命令行(这当然会产生流输出的,我会处理) 。
I would like to prompt the user to type in their password, assign it to a shell variable, and then use that variable to construct the command line of the accessing program (which will of course produce stream output that I will process).
我在伯恩/猛砸一个合理的主管外壳程序员,但我不知道如何接受用户的输入,而无需其显示到终端(或者有它采用呼应字符)。
I am a reasonably competent shell programmer in Bourne/Bash, but I don't know how to accept the user input without having it echo to the terminal (or maybe having it echoed using '*' characters).
任何人都可以在这方面帮助?
Can anyone help with this?
推荐答案
下面是另一种方式来做到这一点:
Here is another way to do it:
#!/bin/bash
# Read Password
echo -n Password:
read -s password
echo
# Run Command
echo $password
的读-S
将关闭回声你。只需更换回声
与您要运行该命令的最后一行。
The read -s
will turn off echo for you. Just replace the echo
on the last line with the command you want to run.
这篇关于如何从shell脚本中的密码,而不回显的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!