$var: Difference between revisions

From Scriptwiki
Jump to navigation Jump to search
Aca20031 (talk | contribs)
No edit summary
 
mNo edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Returns information about currently set [[:Category:Variables|variables]], [[Local Variables|local]] or [[set]].
Returns information about currently set [[:Category:Variables|variables]], [[Local Variables|local]] or [[set]].


  $var(variable name [,N])[.value|.local]
  $var(variable name [,N])[.value|.local|.secs]


* Variable name is a wild card value.
* Variable name is a wild card value.
Line 10: Line 10:
** Value if .value is specified
** Value if .value is specified
** If .local is specified, returns [[$true]] or [[$false]] based on whether or not the matching variable is a [[Local Variables|local variable]]
** If .local is specified, returns [[$true]] or [[$false]] based on whether or not the matching variable is a [[Local Variables|local variable]]
==Examples==
How to search through local variables only:
[[var]] %i = 1
[[while]] ($var(%varwildcard*,%i).local) {
  [[echo]] -ag $var(%varwildcard*,%i) is a local variable
  [[inc]] %i
}
Find out how much is left on a timed variable (set with -u switch)
  ;set a variable, that will be unset in 2 minutes
  [[set]] -u120 %i Test
  ;Later you can use this:
  [[echo]] -ag $var(%i,1).secs


==See Also==
==See Also==
[[set]] [[var]] [[Local Variables]]
* [[set|/set]] - sets global variables
* [[var|/var]] - sets local variables
* [[Local Variables]]


[[Category:Variables]][[Category:Remote Identifiers]]
[[Category:Variables]][[Category:Remote Identifiers]]

Latest revision as of 19:19, 15 February 2015

Returns information about currently set variables, local or set.

$var(variable name [,N])[.value|.local|.secs]
  • Variable name is a wild card value.
  • N tells us we want the Nth matching variable.
    • N is 0 by default, and therefore can be used to check for existence without it
  • Returns
    • Variable name by default
    • Value if .value is specified
    • If .local is specified, returns $true or $false based on whether or not the matching variable is a local variable

Examples

How to search through local variables only:

var %i = 1
while ($var(%varwildcard*,%i).local) {
  echo -ag $var(%varwildcard*,%i) is a local variable
  inc %i
}


Find out how much is left on a timed variable (set with -u switch)

 ;set a variable, that will be unset in 2 minutes
 set -u120 %i Test

 ;Later you can use this:
 echo -ag $var(%i,1).secs 


See Also