append(n)

πŸ“¦
version 9.0.3 Β· 2 versions
, in alpine 3.23, alpine 3.24, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

🌸 NAME 🌸

append β€” appending to a variable, bestie, it's literally what it does πŸ’…


✨ SYNOPSIS ✨

append varName ?value value value ...?

πŸ’– DESCRIPTION πŸ’–

Okay so here's the tea, gorgeous: append takes all of those value arguments and tacks them onto the current value of the variable called varName. That's it. That's the whole vibe. πŸŽ€

And if varName doesn't exist yet? No worries, no cap β€” it just gets created, and its brand-new value is the concatenation of all the value arguments. Instant main character energy. ✨

Now, plot twist for the array girlies: if varName points at an element that doesn't exist, of an array that has a default value set, then the concatenation of that default value and all the value arguments is what gets stored in the array element. Slay. πŸ¦‹

The result of this command β€” like, what it actually hands back to you β€” is the new value that got stored in the variable varName. So you always know what you're working with. πŸ’œ

Real talk though, why is this iconic? Because it's the efficient way to build up long variables incrementally. The way that append a $b is so much more efficient than set a $a$b when $a is long… it's giving optimized. πŸ”₯


🌈 EXAMPLE 🌈

Building a string of comma-separated numbers piecemeal using a loop, because sometimes you gotta assemble the fit one accessory at a time:

set var 0
for {set i 1} {$i<=10} {incr i} {
    append var "," $i
}
puts $var
# Prints 0,1,2,3,4,5,6,7,8,9,10

Look at that output. 0,1,2,3,4,5,6,7,8,9,10. Ate. πŸ˜­πŸ’–


πŸ‘‘ SEE ALSO πŸ‘‘


πŸ“ KEYWORDS πŸ“

append, variable


okay bestie, that's the whole page β€” go forth and concatenate responsibly 🫢✨

this little love letter to append(n) comes to you straight from the Tcl built-in commands, manual page append(n) β€” written with so much affection, and honestly it's giving timeless because it's still exactly this good πŸ’…πŸ§š

πŸ“¦ where this page comes from