Novice WRspice users may be confused by the different interpretations of shell variables and vectors. Any variable can be defined with the set command, and undefined with unset. If defined, the value of the variable is the string, if given. For example, if
set a = 10*2is entered, the value of a (obtained as $a) is the string ``10*2'' and not the integer 20.
Some internally used variables have boolean values, such as
set unixcomwhich if set causes certain modes or functions to be active.
Vectors, however, always have numeric values, and can be created with let and compose, and deleted with unlet. If one enters
let a = 10*2,or more simply
the value of the vector a is 20. Note that the ``let'' is generally optional when assigning vectors.
a = 10*2
At the risk of adding confusion, it should be noted that in recent WRspice releases, the set command can also be used to assign values to vectors. The syntax
set &vector = value
is equivalent to
let vector = value
Vectors can be set to shell variables, in which case they take on the interpreted numerical values. For example,
set a=10*2would assign the string 10*2 to the shell variable a, but the vector b would contain the value 20.
b = $a
The inputs to most commands are vectors, however some commands, such as echo, substitute for shell variables. For example,
set a = "foo"would print ``foobar''.
set b = "bar"
echo $a$b
Shell variables are expanded by echo, and in WRspice input when sourced. If the value of a vector is needed in shell expansion, then the special prefix $& should be added. This tells the shell interpreter that the following symbol is a vector, to be replaced by its value. For example,
let a = 2.0e-2will print 2.00000e-2. However
echo $&a
let a = 2.0e-2would give an error message (unless a is also a shell variable), and
echo $a
let a = 2.0e-2would print ``a''.
echo a
Double quotes will cause multiple tokens to be taken as one, for example
set a = "a string"will set a accordingly, whereas
set a = a stringwill set shell variable a to ``a'' and shell variable string to boolean true.
Single quotes do about the same thing, but suppress shell variable expansion. For example:
set a = fooand
set b = bar
echo $a $b
set a = foowould print ``foo bar'', whereas
set b = bar
echo "$a $b"
set a = foowould print ``$a $b''.
set b = bar
echo '$a $b'
In the present version, $ can not be nested. For example,
set a = fooprints ``$a$b'', not ``foobar''. However,
set b = bar
set c = '$a$b'
echo $c
set a = foodoes print ``foobar'' (the value of c).
set b = bar
set c = $a$b
echo $c
Shell variables that are lists are referenced with zero-based index, for example
set a = ( aa bb cc )prints ``bb''.
echo $a[1]
Actually, what can be in the brackets is [lo-hi], where lo defaults to 0 and hi defaults to the length - 1. If lo > hi, the list is reversed.
If the reference is to a vector, as in
compose a values .1 .2 .3the index is also zero-based, so ``2.0000e-1'' is printed.
echo $&a[1]
The [] subscripting is interpreted a little differently by the shell and by the vector parser. If a variable starts with $, as in $&value[], the [] is interpreted by the shell parser. In this case, the terms inside [] must be interpreted as shell variables, with the (optional) low-high notation. In a vector expression, i. e. , one using value[], the terms inside [] will be interpreted as vector expressions, with the optional low,high notation. Thus,
if (value[index] = 0)is perfectly legal for vectors value and index. Also, equivalently,
if ($&value[$&index] = 0)is also ok, though not as efficient. However
if ($&value1[index] = 0)is an error, as the shell parser does not know that index is a vector.
Shell variables can be used freely in vector expressions, however one must keep in mind how the variables are interpreted. During parsing, the shell variables are evaluated, and their values put back into the expression as constants. Then the expression is evaluated as a vector expression.