我必须在 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/