I have a very long string that is split in chunks. I want to append them to a file without putting the newline character using bash.
Example:
First append
cat >> abc.sh << EOL
echo "bla bla"
ifcon
EOL
Second append
cat >> abc.sh << EOL
fig -a
uname -a
EOL
And the file abc.sh should be:
echo "bla bla"
ifconfig -a
uname -a
and not
echo "bla bla"
ifcon
fig -a
uname -a
How can I achieve this?
Best Answer
<<
always includes a trailing newline (except for an empty here document).You'd need to do either:
Or use a command that removes the trailing newline character instead of
cat
:(Or
perl -pe'chomp if eof'
)Or, where here-documents are implemented with temporary files (
bash
,zsh
,pdksh
, AT&Tksh
, Bourne, notmksh
,dash
noryash
), on GNU/Linux systems, you could do: