
터미널을 사용하여 이라는 tcl 코드가 포함된 스크립트를 실행하려고 합니다 myscript.tcl
. 내가 따르고 있는 튜토리얼에 따르면 chmod +x myscript.tcl
. ./myscript.tcl
tcl 스크립트에서는 #!/home/localadmin/Desktop
튜토리얼에 따라 스크립트에도 추가했습니다. 그러나 실행하면 오류가 발생합니다 Invalid Operation
. 왜 이런 일이 발생하며 어떻게 해결할 수 있나요?
정확한 오류:E: Invalid operation ./myscript.tcl
튜토리얼 링크:https://www.youtube.com/watch?v=U5m_vuBzdZE&list=PL7616FA0112D74AD3&index=2, 1:10 참조
코드 :
#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
후속 조치:
내가 가지고 있는 또 다른 스크립트 -
#!/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"]
동일한 오류가 발생합니다: E: Invalid operation ./lesson3.tcl
. 원본 게시물에서 이 새 파일에 있는 동일한 내용을 사용하여 shebang
문제를 해결했지만 이 새 파일을 실행하는 동안 여전히 같은 오류가 발생합니다.
답변1
귀하의 스크립트가 실행되지 않는 이유는 귀하의 스크립트가 완전히 잘못되었기 때문인 것 같습니다 shebang
. 요점은 컴파일러가 신경 쓰지 않는 점을 지적 shebang
하면서 스크립트를 실행할 패키지 또는 프로그램을 컴파일러에게 알려주는 것입니다 (내 추측입니다)#!/home/localadmin/Desktop
지금까지는 다른 모든 것이 괜찮아 보입니다(다시 한 번 말씀드리지만 에 익숙하지 않습니다 tcl
). 따라서 스크립트의 첫 번째 줄을 다음과 같이 변경해 보겠습니다.
myscript.tcl
#!/usr/bin/tclsh
my_script.....
이것이 작동하지 않는다고 가정하면 다음을 실행하여 스크립트 실행을 방해하는 오류(예: 구문 오류 등)를 추적할 수 있습니다.
tclsh your_script.tcl
비디오를 시청한 후, 이 튜토리얼은 스크립트 실행 방법에 대한 귀하(실제로 우분투를 실행하고 있다고 가정)와 관련이 없습니다.