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 $()
?