linux - 通过 linux 脚本将输出写入文件?

标签 linux input scripting

我必须在 linux 中编写一个脚本,将一行文本保存到一个文件中,然后追加一个新行。我目前拥有的是这样的:

read "This line will be saved to text." Text1
$Text1 > $Script.txt
read "This line will be appended to text." Text2
$Text2 >> $Script.txt

最佳答案

脚本的主要好处之一是您可以自动化流程。使用 阅读就像你已经摧毁了它。你可以接受来自用户的输入而不 失去自动化:

#!/bin/sh
if [ "$#" != 3 ]
then
  echo 'script.sh [Text1] [Text2] [Script]'
  exit
fi
printf '%s\n' "$1" "$2" > "$3"

关于linux - 通过 linux 脚本将输出写入文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30700858/

相关文章:

linux - Bash - 通过运行第二个命令更新终端标题

c - 线程之间是否可以通过LINX进行通信?

css - 更改高度后如何换行和对齐?

python - 这行代码中的[0]是什么意思?

javascript - 取 1 到 10 之间的随机整数,然后提示用户输入猜测数字

unix - 可移植社帮线

c++ - Bison-3.0.4 'make check' 中的 Linux From Scratch 错误

c - 嵌入式 linux,应用程序状态卡住,重新启动

bash - 是否可以将 gnu 的输出与 grep 并行着色?

bash - 每个日期创建一个文件,仅包含与该日期相对应的文件名