$var » History » Version 8
Per Amundsen, 02/23/2023 07:56 PM
| 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 | 8 | Per Amundsen | table(ktable). |
| 14 | |*Parameter*|*Description*| |
||
| 15 | | %var | Variable to match. | |
||
| 16 | | [N] | If N = 0, number of matched variables (default), otherwise the Nth match. (optional) | |
||
| 17 | 1 | Per Amundsen | |
| 18 | *Properties* |
||
| 19 | |||
| 20 | 8 | Per Amundsen | table(ktable). |
| 21 | |*Property*|*Description*| |
||
| 22 | | .value | The variable value. | |
||
| 23 | | .local | [[$true]] if the variable is a local variable, otherwise [[$false]]. | |
||
| 24 | | .secs | Number of seconds until the variable is unset (if autounset is on). | |
||
| 25 | | .unset | Number of seconds until the variable is unset (if autounset is on). | |
||
| 26 | 1 | Per Amundsen | |
| 27 | *Examples* |
||
| 28 | |||
| 29 | <pre> |
||
| 30 | 4 | Per Amundsen | ; Create a variable. |
| 31 | 1 | Per Amundsen | /set %Example Hello World |
| 32 | |||
| 33 | 4 | Per Amundsen | ; Print number of variables matching '%Example*'. |
| 34 | 1 | Per Amundsen | //echo -ag $var(%Example*, 0) |
| 35 | |||
| 36 | ; Print the name and value from the first match. |
||
| 37 | //echo -ag $var(%Example*, 1) = $var(%Example*, 1).value |
||
| 38 | 2 | Per Amundsen | |
| 39 | ; Delete the variable |
||
| 40 | /unset %Example |
||
| 41 | 1 | Per Amundsen | </pre> |