Programatically created files become NULL in Linux [duplicate]

柔情痞子 提交于 2019-12-13 08:33:30

问题


I've a shell script which create files programmatically by writing the contents of a variable to a file in the memory location.

file=/downloads/fileName.crt
variable="These contents are to be
          written to the file"
echo "$variable" > "$file"

This works fine. I'm able to see that the file is written to and not NULL. But sometimes after running this script and after a reboot, the file contents become NULL. Why is this happening?

Link to full code:

Newly created file becomes NULL on reboot in Linux

This code is running on an industrial mobile Linux computer with very basic configuration.


回答1:


Try to

sync

at the end of the script.



来源:https://stackoverflow.com/questions/46649820/programatically-created-files-become-null-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!