[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Dereferencing a variable means accessing its value. The simplest form of dereferencing is by prepending a dollar sign to the variable name:
foo = 1 print foo => foo print $foo => 1 |
Notice, that in the example above, the first print
statement
understands foo
as a literal string, whereas the second one
prints the value of the variable.
Dereferencing an undefined variable produces error message:
print $x error--> variable `x' used before definition |
Optionally, the variable name may be surrounded by curly braces.
Both $foo
and ${foo}
are equivalent. The use of
the latter form is obligatory only when the variable name coincides
with one of the reserved keywords (see section 13.2.3 Reserved Keywords).
It also can be used to resolve ambiguity between using dash as
a part of user name and as a subtraction operator:
long-name = 2 $long-name => 2 $long-name-1 error--> variable `long-name-1' used before definition ${long-name}-1 => 1 $long-name - 1 => 1 |
We recommend to always surround `-' with whitespace when it is used as arithmetic operator.
The ${}
notation also permits some operations similar to
shell variable substitution.
$x error--> variable `x' used before definition ${x:-1} => 1 x = 2 ${x:-1} => 2 |
$x error--> variable `x' used before definition ${x:=1} => 1 $x => 1 |
$x error--> variable `x' used before definition ${x:?} error--> x: variable unset ${x:?foobar} error--> foobar |
radtest
prints text (or a default message, if it
is empty), reads the standard input up to the newline character
and returns the value read. Otherwise, the value of the variable
is returned. This notation provides a convenient way for asking
user to supply default values.
${x::} -| (<teletype>:1)x? ${x::Enter value of x: } -| Enter value of x: |
${variable::text}
, with the exception that the input
value will not be echoed on the screen. This notation provides a
convenient way for asking user to supply default values for variables
(such as passwords, shared secrets, etc.) while preventing them from
being compromised.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |