Skip to content

Remove trailing empty newline from rendered multi-line strings #1018

Closed
@tgdfool2

Description

Hi All,

Is there an easy way to remove the trailing empty newline that is added in multi-line strings?

Given the following code:

local script = |||
  case "$ver" in
    %(current)s)
      echo "Same"
      exit 0
      ;;
    %(upgrade)s
    *)
      echo "Wrong"
      exit 2
      ;;
  esac
|||;

script % {
  current: '10',
  target: '20',
  upgrade: (if $.current != '20' then
  |||
    %(target)s)
        echo "Different"
        exit 1
        ;;
  ||| % { current: $.current, target: $.target } else ''),
}

It produces the following output:

case "$ver" in
  10)
    echo "Same"
    exit 0
    ;;
  20)
    echo "Different"
    exit 1
    ;;

  *)
    echo "Wrong"
    exit 2
    ;;
esac

I would like to get rid of the empty line that was added between the 20 and * cases. Is there an easy way to do this?

Thanks in advance for your help!

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions