FreeKB - remove new lines from a variable
Bash Shell Scripting - remove new lines from a variable

Let's say you have a varialbe (foo in this example) that contains new lines.

foo="line 1
line 2
line 3"

 

To remove all of the new lines.

foo=${foo||$'\n'|}

 

To remove only the very last new line.

foo=${foo%$'\n'}

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 786d5 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |