Remove newline from variables set by script blocks

I have two script blocks:

The first sets a variable FOO using:

echo "BAR"

In the next script block I have:

echo "__{{var.FOO}}__"

which outputs:

__BAR
__

I can remove the newline using:

clean=$(echo "{{var.FOO}}"| tr -d '\n')
echo "__${clean}__"

Just wondering if there’s an easier way to remove the newline. Or whether this is expected behaviour.

Thanks!

You can use a filter:

echo "__{{var.FOO | trim}}__"

I’m working on some features to make this a little easier.

3 Likes