0

Trivial question. What is the most elegant function myfunction that allows to produce the following output?

# myfunction "a
b
c
d"
a%0Db%0Dc%0Dd%0D
user123456
  • 4,758
  • 11
  • 52
  • 78

1 Answers1

1

Using parameter expansion - substitution:

myfunction () {
    echo "${1//$'\n'/%0D}"%0D
}
choroba
  • 45,735
  • 7
  • 84
  • 110