I have rbenv (ruby version manager) installed on machine and it works like that:$ rbenv local2.3.1Writing to stdout the local version of my ruby. I want to rescue this version and declare it in a variable to reuse in another occasion.$ declare -r RUBY_DEFINED_VERSION=$(rbenv local)$ echo Using ruby version $RUBY_DEFINED_VERSIONUsing ruby version 2.3.1It works!But I don't want to use a subshell to do the work (using $() or ``). I want to use the same shell and I don't want to create a tmp file to do the work.Is there a way to do this?Note: declare -r is not mandatory, it can be a simple var=FOOBAR.
Capture the output of a shell function without a subshell
shell;variable;command substitution;subshell