I tried these ways to append content to a file:
printf "\nsource ~/script.sh" >> /etc/bash.bashrc
echo -e "\nsource ~/script.sh" >> /etc/bash.bashrc
cat >> "/etc/bash.bashrc" <<< "source ~/script.sh"
All three ways work. I find the cat
herestring less comfortable as one needs to read it from the end (after cat
append this[end]
to[start]
).
All way don't automatically break the line and the \n
syntax for printf
and echo
is one I'd personally use as last resort. Moreover, I don't know of any way to add a newline for an herestring, and found no such way in this documentation.
What I seek is a utility that goes down one line automatically without the need to add any argument or syntax. I tried to read on nix text processing utilities, but found nothing like what I seek. Do you know such a utility?