我有一个 bash 函数,它将文件作为参数,验证文件是否存在,然后将来自 stdin 的任何内容写入文件。天真的解决方案适用于文本,但我遇到了任意二进制数据的问题。
echo -n '' >| "$file" #Truncate the file
while read lines
do # Is there a better way to do this? I would like one...
echo $lines >> "$file"
done
Run Code Online (Sandbox Code Playgroud)