Var » History » Revision 14
Revision 13 (Per Amundsen, 12/29/2018 09:25 AM) → Revision 14/21 (Per Amundsen, 12/29/2018 09:25 AM)
_Added in 1.8.8_
*/var [-gnsp] <%var> [[= ]value]*
Sets the value of local variable %var to the specified value.
Syntax can be either _var %var = value_ or _var %var value_.
Multiple variables can be set in one line using comma as separator, _var %var1 = value, %var2 = value2_.
_See also [[/set]], {{/unset]]._
*Switches*
-s - Display variable assignment value.
-g - Creates a global variable instead.
-n - Treat the value as plain text, even if arithmetic operators are used.
-i - Initializes a variable only if it does not already exist as a local or global variable.
-p - Permits value to be 2 literal double quotes and permits value to end with a single [[$chr]](32) space. Also enables -n switch behavior.
*Parameters*
<%var> - The variable to set.
[[= ]value] - Value to set the variable to. (can be a single [[Arithmetic Operators|arithmetic expression]])
*Example*
<pre>
alias factorial {
var %result = 1, %x = $1
while (%x) {
var %result = %result * $v1
dec %x
}
return %result
}
;Returns 3628800
//echo -ag $factorial(10)
</pre>