Echoing a number?

Solution 1:

It's a matter of how the shell parses your command, I think. When you do

echo 45>target_size

the shell redirects file descriptor 45 to filetarget_size and then executes echo with no arguments.

If instead you do

echo 45 >target_size

it redirects the standard output descriptor to file target_size and then executes echo 45.

TL;DR add whitespace before the redirection operator.

Solution 2:

@steeldriver's answer is correct - the space between number and redirection operator matters. It seems to be an inconsistent behavior, as in my tests echo 45>output.txt writes 45 to file on ksh93 and dash shells.

As alternative you could always use tee command with here-string operator <<<.

tee  output_file.txt <<< "45"

Or with those shells that don't have <<< operator, echo 45 | tee output_file.txt