When I echo $something >> file.txt, a new line will be append to the file.
echo $something >> file.txt
What if I want to append without a new line?
var="hello world"; echo $var
var="hello world"; IFS='l'; echo $var
var="-e hello \\n world"; echo $var
That's what echo -n is for .
printf is very flexible and more portable than echo. Like the C/Perl/etc implementations, if you do not terminate the format string with \n then no newline is printed:
printf "%s" "$something" >> file.txt
Sign up using Google
Sign up using Facebook
Sign up using Stack Exchange
3 years ago
2 years ago