1

I'm trying to execute a silly 'for' loop in tcl :

for {set i 0} {$i < 10} {incr i} {
      puts $i
}

but I get this error :

line 1: syntax error near unexpected token 'i'
line 1: 'for {set i 0} {$i < 10} {incr i} {'
1
  • 1
    it seems theres nothing wrong with your tcl syntax, if you save the file as test.tcl and execute tclsh test.tcl. Could it be that you use a wrong intepreter, like bash? Commented Jul 22, 2015 at 8:18

1 Answer 1

3

It appears that your script is not being evaluated by Tcl, as that is definitely not an error message that Tcl generates (unless you write code to do so explicitly, i.e., not in this case!) It looks like it might be being evaluated by bash.

Try running your script like this (with the right filename, of course):

tclsh yourscript.tcl

If that works, change the start of your script to read:

#!/usr/bin/env tclsh

After that, just code normally as before.


There are other initial incantations that are somewhat popular:

#!/usr/bin/tclsh
#!/bin/sh
# some comment with a backslash at the end of the line \
exec tclsh "$0" ${1+"$@"}

But these are not as good as using /usr/bin/env which is simple, reliable and portable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.