bash - print character after each line in terminal -
i'd print \ after each line in bash script.
example: output of $k is:
git-core nano apache2
now want install packages using apt. solution is:
sudo apt-get install git-core \ nano \ apache2
how add character?
as suggested, may looking @ wrong solution problem.
you can replace new line characters $k spaces:
k=$(echo "$k" | tr '\n' ' ')
better yet, can take advantage of bash word parsing, knowing apt package names don't have spaces in names (and assuming sure $k contains package names, separated newline):
sudo apt-get install $k
the lack of quoting $k make bash re-parse newlines regular word separators (spaces).
if, other reason, really really want add backslash end of each line, can use sed:
echo "$k" | sed 's/$/\\/'
Comments
Post a Comment