On Jan 28, 2012, at 13.15, Randy Schultz wrote:
so there shouldn't have been a NL in the file, yet the 0a is there.
quite the contrary, actually.
while there may be nuances depending on which echo you're using [stand alone program for a given os or a given shell builtin], as a general rule, you need to supply -n to the command to prevent a newline from being appended. as far as reading it back after assigning the string to a variable, that is how many shells handle words and their adjacent whitespace, bash being a popular example:
echo 'string\n\n\n\n\n\n\n\n\n\n\n' > pwf
wc -l pwf
12 pwf
p=$(cat pwf); echo "|${p}|"
|string|
Just for grins tho', your thoughts got me thinking. I just ran an md5 on the file and compared it to just the string. Well lookee here, they're different. Run od on the file and !surprise - the NL shows up.
hashing the contents or printing octal representations are fine, but this can be demonstrated with just cat, on most systems:
echo 'string' > pwf; cat pwf
string
echo -n 'string' > pwf; cat pwf
string>
regards -b