linux - Shell 脚本,回显消息后在同一行读取

按照我正在执行的 shell 脚本进行操作

#!/bin/sh

echo "Enter [y/n] : "
read opt

它的输出是

Enter [y/n] : 
Y

我希望变量应该在下面的同一行中读取

Enter [y/n] : Y

我想应该很简单,但我是 bash 脚本的新手。

最佳答案

解决方法:read -p "Enter [y/n] :"opt

来自帮助阅读:

  -p prompt output the string PROMPT without a trailing newline before
        attempting to read

https://stackoverflow.com/questions/9720168/

相关文章:

linux - 如何将文件夹中的文件列表发送到Linux中的txt文件

linux - 使用包管理器时如何管理 Perl 模块?

c++ - pthread互斥体的开销?

linux - 用户脚本位置 linux (debian etch)

linux - 禁用内存地址的随机化

linux - 安装 gitLab 缺少现代化工具?

linux - 为什么在 find 命令中使用 dirname 会为每个匹配项提供点?

linux - 从命令行导入 PostgreSQL CSV

ruby - Gemfile.lock 写入错误,权限?

windows - 帮助我让我的 windows cmd.exe 控制台更像一个 Linux 终端