$var » History » Version 7
Per Amundsen, 11/03/2020 06:16 AM
| 1 | 1 | Per Amundsen | _Added in 1.9.0_ |
|---|---|---|---|
| 2 | |||
| 3 | *$var(%var,[N])* |
||
| 4 | |||
| 5 | Returns the Nth matching variable name. |
||
| 6 | |||
| 7 | 5 | Per Amundsen | _Searches both local and global variables, [[Scripting_Wildcards|wildcards]] can be used._ |
| 8 | 1 | Per Amundsen | |
| 9 | 7 | Per Amundsen | _See also [[/var]], [[/set]], [[/unset]], [[/inc]], [[/dec]]._ |
| 10 | |||
| 11 | 1 | Per Amundsen | *Parameters* |
| 12 | |||
| 13 | %var - Variable to match. |
||
| 14 | [N] - If N = 0, number of matched variables (default), otherwise the Nth match. (optional) |
||
| 15 | |||
| 16 | *Properties* |
||
| 17 | |||
| 18 | .value - The variable value. |
||
| 19 | .local - [[$true]] if the variable is a local variable, otherwise [[$false]]. |
||
| 20 | .secs - Number of seconds until the variable is unset (if autounset is on). |
||
| 21 | 6 | Per Amundsen | .unset - Number of seconds until the variable is unset (if autounset is on). |
| 22 | 1 | Per Amundsen | |
| 23 | *Examples* |
||
| 24 | |||
| 25 | <pre> |
||
| 26 | 4 | Per Amundsen | ; Create a variable. |
| 27 | 1 | Per Amundsen | /set %Example Hello World |
| 28 | |||
| 29 | 4 | Per Amundsen | ; Print number of variables matching '%Example*'. |
| 30 | 1 | Per Amundsen | //echo -ag $var(%Example*, 0) |
| 31 | |||
| 32 | ; Print the name and value from the first match. |
||
| 33 | //echo -ag $var(%Example*, 1) = $var(%Example*, 1).value |
||
| 34 | 2 | Per Amundsen | |
| 35 | ; Delete the variable |
||
| 36 | /unset %Example |
||
| 37 | 1 | Per Amundsen | </pre> |