For example, when I run
brew search octave
I don't know which of these to install so I want to check the version of these programs. Is there any way to get it without installing?
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.
You have two versions because one is command-line and the other is a Graphical User Interface (GUI). You can check their versions with the commands below. I use
octave is no longer a cask:
$ brew info octave octave: stable 5.1.0 (bottled), HEAD High-level interpreted language for numerical computing https://www.gnu.org/software/octave/index.html ... $ brew cask info libreoffice libreoffice: 6.3.4 https://www.libreoffice.org/ ...
This solution works immediately and avoids "tapping" and downloading a repo (which as of January 2020 requires entering a Github username and password).