Script Command: SET
SET [-e] <}>| =EXPRESSION
Establish the content of a shell variable. This can be a simple equality (set VAR VAL) or it can be an expression (set VAR=$VAL+1).
Options:
-eexport (see note below) the variable being established.
The expression evaluator handles the following operators in the following priority:
1) Anything enclosed in ()'s as well as variables and functions.
2) Unary + and - signs
3) "To the power of" symbol: ^
4) Times (*), divide (/), and modulus (%)
5) Plus (+) and minus (-)
6) Assignments (=)
The evaluator supports logical functions for shifting and masking (|,&,>,<).
It also supports embedded functions. The current set of functions are:
- hex (VARNAME)to convert a variable to hex (format: "0x%x")
- hex0(VARNAME)to convert a variable to hex (format: "%x")
- hex2(VARNAME)to convert a variable to hex (format: "%02x")
- hex4(VARNAME)to convert a variable to hex (format: "%04x")
- hex8(VARNAME)to convert a variable to hex (format: "%08x")
- rand()to generate a random number (seeded initially with time())
The result is displayed in decimal unless somewhere within the expression the 'hex' function is used.
Examples:
- set VAR=99+5
- set VAR=hex(4000)
- set VAR=(99+$VAR)*4
- set VAR=0x1000>1
- set RAND=rand()
- set RAND10=rand()%10
Note1: The expression must contain no whitespace.
Note2: Under the context of uCon, an exported shell variable means it will be saved to a configuration file if a save is done after being exported. This is convenient for cases where environment variables are configured on the first pass of a script, then on later invocations of uCon that same environment can be restored if the variables are exported.