Get the version of TCL from the command-line?
Asked Answered
S

3

69

I'm looking for a very straight-forward way of getting the version of the TCL installed on a machine from the command-line. For most programming languages, something along the lines of

languagename -v

provides the information that I want. This does not seem to be an option for tclsh.

The TCL FAQ Q.B21 suggests

echo 'puts $tcl_version;exit 0' | tclsh

but I wonder if there is anything more straight-forward and cross-platform? (I suspect that this would fail mightily on a Microsoft Operating System.)

--

EDIT: Just to emphasize that I'm looking for something that can be executed directly from the operating system command-line. There's all kinds of information available once you start tclsh, but I'm trying to avoid that to ease automated discovery.

Studding answered 8/2, 2012 at 19:30 Comment(5)
If you're also looking for the minor version number, use puts [info patchlevel] instead of puts $tcl_version. Also, you don't explicitly need to exit -- Tcl will see the end of the script and exit on it's own.Zohar
Thanks Glenn. That's useful to know.Studding
Would be interesting to know WHY you need the info. Sometimes in Tcl you don't need the info, because STUBS might make any recent (< 12 years) old Tcl acceptable.Coryphaeus
Perfectly reasonable question. I was wondering about the practicality of automating the recording of the programming language version numbers used by my program (bitbucket.org/simonpeter/zadok) as it uses so many different languages that it could get quite time consuming determining the version numbers manually. I had done pretty well figuring out the other languages, but TCL is new to me and tclsh doesn't play like the others do.Studding
tclsh CLI API is horrendous!Garek
P
57

This might sound too simplistic, but if you made a script file that contained the commands:

puts $tcl_version

And then ran tclsh sillyscript.tcl, that would execute on all platforms, assuming binary is in PATH. It certainly isn't fancy or flashy, or even neat, but it satisfies that requirement AFAIK.

====

I got curious, so I tried it and without the quotes:

echo puts $tcl_version;exit 0 | tclsh

Executes just fine on my windows box... maybe platform detection prior to the TCL detection is an option?

Petiole answered 8/2, 2012 at 19:38 Comment(5)
That may end up being the best way to do it. I'll wait to see if any other answers come in, otherwise I'll accept this one. Thanks.Studding
Different platforms have different shell metacharacters, but using a helper script file is easiest of all.Brainpan
Linuxers, copy and paste: echo 'puts $tcl_version;exit 0' | tclshGarek
See other answers that use info patchlevel to retrieve more complete informationTomlinson
You don't need the ; exit 0, and the sinqle-quoted echo version works fine in PowerShell, even though it doesn't in CMD.Erythritol
S
30

you can do this too.

bash-3.2$ tclsh
% puts $tcl_version
8.6
% info patchlevel
8.6.0

but the best way i think is through echo.

echo 'puts [info patchlevel];exit 0' | tclsh
echo 'puts $tcl_version;exit 0' | tclsh

=======

weird when i tried with out the quotes it didn't work for me. running Mac osx

Sealer answered 4/10, 2013 at 19:36 Comment(3)
If you don't put $tcl_version inside single quotes, the bash shell will try and replace $tcl_version with the value from a bash shell variable named tcl_version. Since tcl_version doesn't exist the replacement is a null string, turning "puts $tcl_version" into "puts". Single quotes in the bash shell is like {} in tcl - it stops interpolation.Moreover
Very valuable tip to have added the info patchlevel invocation. This makes a difference for example when installing gcc since there tcl is "necessary to run the GCC testsuite; see the section on testing for details. Tcl 8.6 has a known regression in RE pattern handling that make parts of the testsuite fail. [...] This bug has been fixed in 8.6.1" Version 8.6 is shipped with Ubuntu 14.04 but the minor release number was hard to get.Tomlinson
Correction on the above. The terminology for the version notation is major.minor.patchlevel. So info patchlevel gives the version down to the patch level. Incorrect of me to say that the minor release number was hard to get. The patch level was.Tomlinson
S
13

Depending on your shell, it could be:

tclsh <<< 'puts [info patchlevel]'
Sure answered 11/1, 2016 at 12:29 Comment(1)
The info patchlevel is in my view superior to tcl_version for it gives a more complete version tag.Tomlinson

© 2022 - 2024 — McMap. All rights reserved.