shell脚本从控制台输入MySQL等密码

场景

Linux环境下,某些密码不适合在文件中存储,容易造成密码的泄露,以及密码更改后需要重新编辑脚本,有时候需要用户(运维人员)从控制台输入密码来完成脚本的执行。

案例

1
2
3
4
#!/bin/bash
read -s -p "Enter your password:" pass
echo "your password is $pass"
exit 0
SH

我们将控制台输入的字符赋值给$pass变量,即可执行后续的脚本。
结果:

1
2
3
hao@MacBook-Pro ~ % ./test.sh 
Enter your password:
your password is 123
SH

shell脚本从控制台输入MySQL等密码
https://leehoward.cn/2021/01/02/shell脚本从控制台输入MySQL等密码/
作者
lihao
发布于
2021年1月2日
许可协议