Exploring the different kind of assignments

  1. Whole-line assignments $x=value
    Note that any quotations will not be removed but included as part of the value
  2. Inline assigments using $set $set $x=value
  3. Inline assigments using $set $set $x="value" with value in quotations
  4. Inline assigments using $setval $setval $x=value with or without quotations
  • If the assigned value does not contain variables that can be evaluated, then all three methods produce identical answers.

A. the assigned value is a single variable

$a=A-value
  1. $w=$a
    Whole line assignment results in $w containing: $a
  2. $set $x=$a
    Inline assignment results in $x containing: A-value
  3. $set $y="$a"
    Inline assignment results in $y containing: $a
  4. $setval $z=$a
    Inline assignment using setval results in $z containing: A-value
  • Summary: $set and $setval both evaluate the variable, but quotes and whole-line assigments preserve the string exactly

B. the assigned value begins with a single variable

  1. $w=$a plus more
    Whole line assignment results in $w containing: $a plus more
  2. $set $x=$a-plus-more (set requires no spaces in value if quotes are not used)
    Inline assignment results in $x containing: $a-plus-more
  3. $set $y="$a plus more"
    Inline assignment results in $y containing: $a plus more
  4. $setval $z="$a plus more"
    Inline assignment using setval results in $z containing: A-value plus more
  • Summary: $set fails to do the evaluation. The others work as expected