how do I echo $something >> file.txt without carriage return?
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
If you are using command's output, you can use xargs in combination with echo
/sbin/ip route|awk '/default/ { print $3 }' | xargs echo -n >> /etc/hosts