I'm trying to calculate the SHA1 of different TCL scripts in a folder for version checking (my TCL version is 8.5). I want to do this from within one of the TCL scripts, and print this info into a separate file. I thought I could do something like this:
set repoDir "some/repo/dir"
set scripts_hash [cd $repoDir/scripts; exec sha1sum ./* | sha1sum]
puts $file $scripts_hash
However, exec doesn't allow this? How can I execute a sha1sum shell command from within a .tcl script?
You could either explicitly loop over each element, or put them all together. Here's a loop option:
# ... open $file
set repoDir "some/repo/dir"
foreach f [glob -directory $repoDir -- "*"] {
puts $file [exec sha1sum $f]
}
close $file
and here's a one-shot call to sha1sum
:
# ... open $file
set repoDir "some/repo/dir"
puts $file [exec sha1sum {*}[glob -directory $repoDir -- "*"]]
close $file
The {*}
prefix forces TCL (v8.5+) to expand each of the resulting glob
list items to become individual arguments for sha1sum
.