Var » History » Version 13
Per Amundsen, 12/29/2018 09:25 AM
1 | 1 | Per Amundsen | _Added in 1.8.8_ |
---|---|---|---|
2 | |||
3 | 12 | Per Amundsen | */var [-gnsp] <%var> [[= ]value]* |
4 | 1 | Per Amundsen | |
5 | Sets the value of local variable %var to the specified value. |
||
6 | |||
7 | 6 | Per Amundsen | Syntax can be either _var %var = value_ or _var %var value_. |
8 | 5 | Per Amundsen | |
9 | 9 | Per Amundsen | Multiple variables can be set in one line using comma as separator, _var %var1 = value, %var2 = value2_. |
10 | 5 | Per Amundsen | |
11 | 1 | Per Amundsen | *Switches* |
12 | |||
13 | -s - Display variable assignment value. |
||
14 | -g - Creates a global variable instead. |
||
15 | -n - Treat the value as plain text, even if arithmetic operators are used. |
||
16 | 13 | Per Amundsen | -i - Initializes a variable only if it does not already exist as a local or global variable. |
17 | -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. |
||
18 | 1 | Per Amundsen | |
19 | *Parameters* |
||
20 | |||
21 | <%var> - The variable to set. |
||
22 | 11 | Per Amundsen | [[= ]value] - Value to set the variable to. (can be a single [[Arithmetic Operators|arithmetic expression]]) |
23 | 1 | Per Amundsen | |
24 | *Example* |
||
25 | |||
26 | 2 | Per Amundsen | <pre> |
27 | 3 | Per Amundsen | alias factorial { |
28 | 1 | Per Amundsen | var %result = 1, %x = $1 |
29 | while (%x) { |
||
30 | var %result = %result * $v1 |
||
31 | dec %x |
||
32 | } |
||
33 | return %result |
||
34 | } |
||
35 | 3 | Per Amundsen | |
36 | ;Returns 3628800 |
||
37 | //echo -ag $factorial(10) |
||
38 | 2 | Per Amundsen | </pre> |