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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -