recalculate length whenever write to shell.