I have rbenv (ruby version manager) installed on machine and it works like that:
$ rbenv local
2.3.1
Writing 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_VERSION
Using ruby version 2.3.1
It 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.