问题
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