0

I have this command in my tcl script

file delete {*}[glob -nocomplain /tmp/*.list]

It deletes a file in /tmp directory with .list extension. It is working perfectly fine when running it using tclsh filename.

But when I compiled a tcl standalone application (The Simplest Steps to Converting TCL TK to a Stand Alone Application), it throws me an error saying it is an invalid command.

Any idea?

Community
  • 1
  • 1
StarCoder17
  • 175
  • 6
  • 17

1 Answers1

1

The {*} syntax was added in Tcl 8.5. It is likely your standalone version is older given the error. You should upgrade that to 8.5 or 8.6 or you can replace the problem command with a backwards compatible equivalent:

eval [linsert [glob -nocomplain /tmp/*.list] 0 file delete]]

The linsert ensures that the output of the glob command is a properly formed list with the file delete prefixed to the front such that calling eval on the list will result in calling file delete with all the filenames and not evaluating anything nasty in the filenames themselves.

This sort of problem is why the expansion syntax ({*}) was added.

patthoyts
  • 32,320
  • 3
  • 62
  • 93