linux - 读取输入而不回显不起作用(bash Shell 脚本)

标签 linux bash shell echo

“-s”开关在 bash shell 脚本中不起作用。它会抛出错误而不提示输入密码。

使用:Ubuntu 16.04.6 LTS

我错过了什么吗?

#!/bin/bash

echo "Enter password"
read -s password
echo "password:" $password

输入密码 test.sh:4:读取:非法选项-s 密码:

最佳答案

您正在使用 sh 运行脚本,而不是使用提供相关功能的 bash 。直接使用 bash 调用脚本:

bash test.sh

或者使文件可执行,以便解释器读取您的 shebang:

chmod +x test.sh    # only required once
./test.sh

除非您在某些特殊目录中运行实际的 POSIX shell 脚本,否则不需要 .sh 扩展名。

关于linux - 读取输入而不回显不起作用(bash Shell 脚本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56849703/

相关文章:

linux - Linux内存管理器中的"Weak reference"?

json - Linux bash 解析 json : Get first & last date

bash - 如何从文件中读取前 n 行和后 n 行?

linux - Shell 脚本支持——不同 URL 上的多个 nslookups

linux - 从目录打开最新文本文件的脚本

c - 如何从单个流程实例创建多个网络 namespace

java - 如何从基于 Java 的代码运行 shell 脚本

shell - 从文本文件列表中提取

linux - 我可以用什么来捕获我在 bash 中运行的每个命令(a-la 历史)

bash - 在目录上递归计算 .gz 文件的行数?