
ターミナルを使用して、 という名前の 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=21: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
)。そこで、スクリプトの最初の行を次のように変更してみます。
スクリプト
#!/usr/bin/tclsh
my_script.....
これが機能しない場合は、スクリプトの実行を妨げるエラー(構文エラーなど)を以下を実行して追跡できます。
tclsh your_script.tcl
ビデオを見た後、このチュートリアルは、スクリプトの実行方法についてはあなたには関係ありません(実際にUbuntuを実行していると仮定します)。