
Usando la terminal, estoy intentando ejecutar un script que contiene el código tcl llamado myscript.tcl
. Según el tutorial que estoy siguiendo, debo escribir chmod +x myscript.tcl
y luego ejecutar el código usando ./myscript.tcl
. Tenga en cuenta que en el script tcl también agregué #!/home/localadmin/Desktop
el script según el tutorial. Sin embargo, al ejecutarlo, aparece el error Invalid Operation
. ¿Por qué ocurre esto y cómo puedo solucionarlo?
Error preciso:E: Invalid operation ./myscript.tcl
Enlace al tutorial:https://www.youtube.com/watch?v=U5m_vuBzdZE&list=PL7616FA0112D74AD3&index=2, consulte 1:10
El código :
#variables set to integer will ALWAYS be integer, cannot assign strings
set x 3
set y 4
#$x means the value of x
#whatever happens after expr will take it as a mathematical expression
#whatever inside brackets is executed
set z [expr $x + $y]
#text is option for command label
#the . represents anything coming from main window after execution
label .sum -text "z is $z"
label .myname -text "My NAME is RAND PAUL"
incr z
label .increment -text "incrementing z -> $z"
#pack puts the previous labels on te main window
#without pack, will discard the labels
pack .myname .increment .sum
Hacer un seguimiento:
Otro guión que tengo...
#!/usr/bin/tclsh
#Lesson 3 tk/tcl lists
set to_do [list]
lappend to_do "name"
lappend to_do "is"
lappend to_do "bobby"
lappend to_do "jones"
set num [list 0 1 2 3 4 5 6 7 8 9 10 11]
puts $to_do
puts $num
puts "index 0 is [lindex $to_do 0]"
puts "index 3 is [lindex $to_do 3]"
puts "replacing one element..."
puts [lreplace $num 3 3 [list 30 40 50 60]]
puts "replacing a range of elements from index 3 till ndex 6 => other indexees from 4 till 6 will deleted"
puts [lreplace $num 3 6 [list 30 40 50 60]]
puts "inserting one element at index 1 (2nd element that is)..."
puts [linsert $num 1 "new list element"]
Produce el mismo error: E: Invalid operation ./lesson3.tcl
. Utilicé lo mismo shebang
que se encuentra en este nuevo archivo en la publicación original y lo solucionó, sin embargo, sigo teniendo el mismo error al intentar ejecutar este nuevo archivo.
Respuesta1
Supongo que la razón por la que su script no se ejecuta es porque shebang
está completamente equivocado. El objetivo shebang
es decirle al compilador qué paquete o programa ejecutar el script y #!/home/localadmin/Desktop
no apunta a nada que le interese al compilador (supongo)
Todo lo demás parece correcto hasta ahora (nuevamente no estoy familiarizado con él tcl
). Así que intentaría cambiar la primera línea del script a algo como lo siguiente
miscript.tcl
#!/usr/bin/tclsh
my_script.....
Suponiendo que esto no funcione, puede rastrear cualquier error que tenga y que impida que se ejecute el script (como errores de sintaxis y similares) ejecutando
tclsh your_script.tcl
Después de ver el video, este tutorial no le corresponde (suponiendo que realmente esté ejecutando ubuntu) sobre cómo ejecutar el script.