For example, when I run
brew search octave
I don't know which to install so I want to check the version of these programs. Is there any way to get it without installation.
You can get information on each of the hits:
brew info homebrew/science/octave brew info Caskroom/cask/octave
In both cases, these may require you to "tap" the containing levels, but it gives you the command to run for each as needed.
From the first package information, you should get an info URL of https://github.com/Homebrew/homebrew-science/blob/master/octave.rb and then could inspect the source of that octave installation. Repeat for the cask and then you can decide or not to install one or the other.