In which case, echo can append the NULL characters unexpectedly

351 Views Asked by At

I'm working on a mini machine(MEM: 256M), its OS is linux.

I wrote a bash script, which would be executed while the system is booting (executing command is added into /etc/rc.local).

In this script, there is a command echo "a_long_string" >> /etc/custom_config.

a_long_string is a string, whose length is 248.

To test the script, I rebooted the system many times and I found an issue:

Sometimes, the command echo "a_long_string" >> /etc/custom_config will append 248 NULL characters plus the a_long_string, which means that, normally after executing this command, we could find the a_long_string at the end of the file /etc/custom_config, but sometimes I do find that the appended string becomes as below:

^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@...a_long_string

I'm trying to figure out what happened. Does echo a long string may cause some issue like this on a small RAM system?

0

There are 0 best solutions below