0

I have a variable 'p' which has values 'first second third'

echo $p
first second third

I want to make this output as below

echo $p
first
second
third
Sajana
  • 3
  • 4
  • @Aaron That is definitely the wrong duplicate, but this is a common FAQ as such. Maybe see also [the `bash` tag info page](/tags/bash/info) for links to many common beginner questions. – tripleee Oct 12 '22 at 05:52
  • 1
    This was more about substitutions than storing newline characters in variables. And the use of `printf` instead of `echo` is not the solution. I don't think closing questions for wrong reasons is a good thing. – Renaud Pacalet Oct 12 '22 at 05:55
  • 1
    @Sajana: Try: `echo "${p// /$'\n'}"`. Explanation: `"${p// /$'\n'}"` substitutes all spaces in `p` with a newline character (`$'\n'`). – Renaud Pacalet Oct 12 '22 at 05:57
  • 1
    `printf "%s\n" $p` – user1934428 Oct 12 '22 at 06:24

0 Answers0