puts hello
puts hello world
puts stdout hello
puts stderr hello
puts "hello world"
expr 1 * 1
set a 5
puts $a
puts $abc
puts ${a}bc
puts $a$a$a
info exists a
info exists unbekannt
append a 6 7 8
set a [expr 1 * 1]
puts [expr $a * $a]
puts \[expr\ \$a\ *\ \$a\]
puts abc\ndef
puts "hello world
good bye
"
set a 5
set b 7
puts "$a * $b = [expr $a * $b]"
puts {$a * $b = [expr $a * $b]}
puts {hello world
good bye
}
expr 1 < 5
expr ! ( 1 < 5 )
expr {"Hellmut" < "Oskar"}
set a 5
set b 7
if {$a < $b} {
set res "a ist kleiner als b"
} else {
set res " a ist groesser als b"
}
puts $res
set a emil
set b egon
if {"$a" == "$b"} {
set res "a ist gleich b"
} else {
set res "a ist ungleich b"
}
puts $res
for {set i 1} {$i < 4} {incr i} {
puts "Das sage ich Dir zum $i. Mal!"
}
set res ""
foreach i {Vanille Erdbeer Schoko} {
append res "Eine Kugel $i bitte!\n"
}
puts $res
set i 1
while {$i < 5} {
puts "Das $i. Mal\n"
incr i
}
proc square {x} {
return [expr $x * $x]
}
proc times {x y} {
return [expr $x * $y]
}
proc echoargs args {
set cnt 1
set res ""
foreach i $args {
append res "Der $cnt. Parameter hat den Wert: \"$i\"\n"
incr cnt
}
puts $res
}
proc p0 {} {
return "dies ist eine Prozedur ohne Parameter"
}
set gv "this is a global variable"
proc p {} {
global gv
puts $gv
}
exec date
exec date +%H:%M
exec ps -l
set time [exec date "+%H:%M"]
set status [exec ps -l]
set this_file [exec cat Kommandos.tcl]
if {[catch {exec fortune} res]} {
puts stderr "Fehler: kein fortune Programm"
set res ""
} else {
puts stderr "fortune erfolgreich aufgerufen"
}
puts $res
set a "set x"
set b "5"
eval $a $b
puts "$x"
echoargs $a
eval echoargs $a
regexp {[0-9]+} abc-123-def
regexp {[0-9]+} abc-123-def a
regexp {[0-9]+} abc-123-456-789-def a
regexp {([0-9]+)[^0-9]+([0-9]+)} abc-123-456-def a a1 a2
puts $a
regexp {[0-9]+} --123-- a
puts $a
regsub {l} "Elli" m res
puts $res
regsub -all -- {l} "Elli" m res
puts $res
regsub -all -- {([0-9]+)} "123-456-789" {.\1.} res
puts $res
set l {ali berta caesar dolli}
set n1 "Karl Knut"
set n2 "Mueller Luedenscheid"
set l [list $n1 $n2 "$n1 $n2"]
set v1 [lindex $l 0]
set v2 [lindex $l 1]
set len [llength $l]
lappend l "Theo Lingen"
set l
set l2 [linsert $l 1 "Franz Beckenbauer"]
set l
set l2
set l2 [lrange $l 2 end]
set i [lsearch $l abc]
set i [lsearch $l "Karl Knut"]
set l {a b c d e f g}
set l1 [lreplace $l 3 end]
set l2 [lreplace $l 1 2 B C]
set l {a b c d e f g}
set l2 [concat $l $l]
set l3 [lsort $l2]
set result ""
foreach i $l {
append result "Element $i wird verarbeitet\n"
}
split 123.456.789.111 .
split 123.456.789.111 1
split 123.456.789.111 ""
set l [split 123.456.789.111 .]
join $l .
set a(nachname) "Lingen"
set a(vorname) "Theo"
set a(alter) "sehr alt"
puts "Name: $a(vorname) $a(nachname)\nAlter: $a(alter)"
foreach i [array names a] {
puts "a($i) = $a($i)"
}
source ./tcl/setopt.tcl
source ./tcl/format-html.tcl
tag_h1 "die Überschrift"
tag_em "eine wichtige Aussage"
set res ""
foreach i [array names a] {
append res [list set a($i) $a($i)]
append res "\n"
}
set tmpfile [open "tmp.tcl" w]
puts $tmpfile $res
close $tmpfile
source "tmp.tcl"