Difference between revisions of "Var"

From Scriptwiki
Jump to: navigation, search
 
m (links added)
Line 11: Line 11:
 
You can use /var -s to make a variable show the result when a value is set.
 
You can use /var -s to make a variable show the result when a value is set.
  
== Example
+
== Example ==
  
 
First, let's create [[Aliases|alias]] needed later on.
 
First, let's create [[Aliases|alias]] needed later on.
Line 30: Line 30:
 
   
 
   
 
  ; now, let's display %x and %y values
 
  ; now, let's display %x and %y values
  echo -a %x
+
  [[echo]] -a %x
 
  ; returns 10
 
  ; returns 10
  echo -a %y
+
  [[echo]] -a %y
 
  ; returns bar
 
  ; returns bar
  

Revision as of 18:37, 24 August 2005

Var creates the local variable in the current routine and can only be referenced from inside this routine.

The difference between /var and /set is that var creates local variable what only exists while script is executed. Set sets value to variable and stores it there until it's unset. Local variables doesn't overwrite variables set with "set" command values.

You can set multible variables with one set

var %x = foo, %y = bar

Usage of = in syntax is optional

var %x foo

You can use /var -s to make a variable show the result when a value is set.

Example

First, let's create alias needed later on.

alias var_example { var -s %x foo | set -s %y bar }

Now, let's play around.

; set values to variables with set so values exists until they're unset
set %x 10
set %y %x
; value fro %x is copyed to %y (for users from with previous knowledge from scripting)

; call of your own alias
var_example
; displays
; * Set %x to foo
; * Set %y to bar

; now, let's display %x and %y values
echo -a %x
; returns 10
echo -a %y
; returns bar

As we can see, %x still holds it origial value because /var creates only local variable, but %y was overwritten with /set.