“-s”开关不起作用bash shell脚本。它会在不提示输入密码的情况下引发错误。
使用:Ubuntu 16.04.6 LTS
我想念什么吗?
#!/bin/bash
echo "Enter password"
read -s password
echo "password:" $password
输入密码 test.sh:4:读取:非法选项-s 密码:
答案 0 :(得分:2)
您使用sh
而不是bash
运行脚本,脚本提供了相关功能。要么直接使用bash调用脚本:
bash test.sh
或将文件设置为可执行文件,以便解释器读取您的shebang:
chmod +x test.sh # only required once
./test.sh
除非您在某些特殊目录中运行实际的POSIX shell脚本,否则不需要.sh
扩展名。