ENV
result = ENV(expr)
Reads an Environment Variable from the current environment variable-table.
ENV can be used as SUB for setting and deleting Environment Variables and ENV can be used as a FUNCtion for returning a particular Environmet Variable or the whole set of them into an array.
Example 1: Setting and getting Evironment Variables
5
SB1 = "My evironment variable"
SB2 =
'Set Environmet Variables
ENV("SB1=" + SB1)
ENV("SB2=" + SB2)
ENV("SB3=6")
ENV("SB4=\"test\"")
' Get Environment Variables
print ENV("SB1")
print ENV("SB2")
print ENV("SB3")
print ENV("SB4")
Example 2: Querry all Environment Variables
ENV("")
AllEnv =
for a in AllEnv
print a
next
Example 3: (Linux) Querry DESKTOP_SESSION
print ENV("DESKTOP_SESSION") 'i.e will print "plasma" if using KDE
Example 4: Delete a Environment Variable (doesn’t work in Linux)
ENV("SB1=") ' Deletes SB1
Example 5: Using ENV and CHAIN to create a eval-function
' Dedicated to MGA.
' s is any legal SmallBASIC Math Expression as String, e.g. "1 + 2 / 4"
Func eval(s)
Chain "Env " + Enclose("SBEVAL=") + " + Str(" + s + ")"
Val(Env("SBEVAL"))
eval = End Func
' now run few demos:
"1+2")
? eval("Rad(45) * 2")
? eval("PI / 2 + PI")
? eval("0b1111 * Pow(2, 4)")
? eval("Sin(2) * Tan(4) / Cos(6)")
? eval("1 + 2 / 4")
? eval("6 * (Pow(2, 4) * 8)")
? eval("Rad((45 * 3) - 20) * 2") ? eval(
General suggestions using Environment Variables
- Never use names which are already used by the system or another process, such as “PATH”, “HOME”, “PWD”, etc. You should check which variable names are already in use.
- Use short and unique names, such as: “SB1”, SB2” or “SBv1”, “SBv2”, etc. It will keep the environment-variables-table readable, and will save space in the table.
- Don’t create more variables then you need. Reuse any variable which is not used. i.e. if “SB1” is unused anymore, then reuse it.
- On some systems the environment-variables-table is unique for each session (Linux for example) and this may be a bit confusing.
- Environment variables may or may not be case sensitive, i.e. “SB1” may be different then “sb1” on some systems (Linux for example).
Code samples using ENV
System
CHAIN
COMMAND
CWD
DELAY
ENV
ENV
EXEC
EXPORT
FRE
HOME
IMPORT
INCLUDE
MAXINT
NIL
OPTION
PAUSE
PI
PROGLINE
RANDOMIZE
RUN
SBVER
SELF
STKDUMP
TROFF
TRON
UNIT
If there is insufficient information on this page and you wish learn more about ENV,
please send an email to smallbasic@gmail.com. You can help to improve information about
ENV by submitting a pull request,
click View Source for details. Note, an offline language reference text file is also available - see the Download section.