Reputation:
I'm trying to remove the final '\n'
character from a string variable.
For example:
string
string
string
\n
should simply become:
string
string
string
A lot of the examples I have seen do this for a file but not a variable.
Any help would be greatly appreciated!
Upvotes: 1
Views: 172
Reputation: 786091
In BASH you can do this to remove last newline:
eol=$'\n'
str="${s%$eol}"
Upvotes: 1
Reputation: 97331
You can use parameter expansion like this:
variable="${variable%$'\n'}"
Upvotes: 3