如何在shell脚本中将用户输入记录到文件中?

The*_*nja 3 scripts

我的朋友向我展示了一个 shell 脚本程序,他在其中打开了该程序,它会提出一个问题,他会输入一个答案。然后它会关闭,但他输入的任何答案都会被转移到文本文档中。

ste*_*ver 5

我建议从类似的事情开始

#!/bin/bash

read -p "Your question here: "

echo "$REPLY" > somefile
Run Code Online (Sandbox Code Playgroud)

read您可以从手册页 ( man bash) 或通过help read在 shell 提示符下键入来阅读有关 bash 命令的更多信息。