Reputation: 1
When using envsubst to replace values in a file, it creates a newline when it appends to a string. How do I prevent it from inserting a newline when saving it to a new file?
Environment Variable:
foo=bar
File:
$foo\\text\\word,$foo\\text2\\word2,$foo\\text3\\word3
Command:
envsubst < test.properties > temp.properties
Undesired output:
bar
\\text\\word,bar
\\text2\\word2,bar
\\text3\\word3
Desired output:
bar\\text\\word,bar\\text2\\word2,bar\\text3\\word3
Upvotes: 0
Views: 915
Reputation: 3739
You can always pipe to tr
to remove the newlines
$ echo "foo\nbar" | tr -d '\n'
foobar
Upvotes: 0
Reputation: 1
Was having a similar issue with a string in file where I need to replace something like this:
my_string_$VAR_that_continues
I managed to solve this protecting the variable name inside the string like this:
my_string_${VAR}_that_continues
And then use the envsubst command normally. Hope it still helps you.
Upvotes: 0