Skip to main content
Clearer title
Link
user137369
  • 584
  • 2
  • 5
  • 15

How to make Zsh differentiatinginterpret \n and ↩ in variable contentsparameter expansion

Source Link
user137369
  • 584
  • 2
  • 5
  • 15

Zsh differentiating \n and ↩ in variable contents

I’m using Zsh’s parameter expansion flags to split a string into an array.

This works:

string="one
two"
array=("${(f)string}")
echo "${array[1]}"

# Returns:
# one

This does not work:

string="one\ntwo"
array=("${(f)string}")
echo "${array[1]}"

# Returns:
# one
# two

How can we make the expansion interpret the \n as a newline?