如何在脚本中添加预定值?

时间:2019-11-26 16:30:28

标签: bash terminal

我有一个命令行提示符,该提示符在运行时要求输入用户名和密码。我希望能够通过变量添加这些值,以便可以在脚本中运行它们。

这是命令。

# Enable the local admin account for FileVault: sudo fdesetup add -usertoadd LOCAL_ADMIN_ACCOUNT

这是提示用户的内容 # End user enters his/her credentials when prompted: Enter the user name: LOCAL_USER Enter the password for user 'LOCAL_USER':

1 个答案:

答案 0 :(得分:0)

将密码保存到脚本文件是个坏主意。

您可以使用期望:

#!/usr/bin/expect

set timeout 20

spawn sudo fdesetup add -usertoadd LOCAL_ADMIN_ACCOUNT
expect "Enter the user name:"
send "yourusername\r\n";
expect "Enter the password for user:"
send "yourpasswd\r\n";
interact

有关更多信息,请运行:

man expect