0

I've got a zsh function that computes a binary sequence and returns it as a string. Simplified:

function make_str() {
   print -n $'\0\1\0\n'
}

myvar="$(make_str "some" "args")" typeset -p myvar

This prints:

typeset myvar=$'\C-@\C-A\C-@'

So my return value is losing the \n at the end, I believe because of the $() I use to capture the function's output. From the zsh docs:

A command enclosed in parentheses preceded by a dollar sign, like ‘$(...)’, or quoted with grave accents, like ‘‘...‘’, is replaced with its standard output, with any trailing newlines deleted.

So, how do I cleanly capture the output of my function in a variable if I can't use command substitution, ie $()?

xdhmoore
  • 145
  • @muru, yes, thank you. Since I have nulls in my output, some of the options don't work but it looks like the good ol' "add an x at the end" is working. – xdhmoore Jul 09 '23 at 00:56

0 Answers0