Access environment variables using the 's property syntax.
Environment Properties#
| Property | Syntax | Description |
|---|---|---|
count | environment's count | Total number of environment variables |
first | environment's first | First env var (full "NAME=value" string) |
last | environment's last | Last env var |
empty | environment's empty | True if no environment variables |
"NAME" | environment's "HOME" | Value of specific env var by name |
Reading Environment Variables#
a text called home is environment's "HOME".
a text called user is environment's "USER".
a text called shell is environment's "SHELL".
Print "Home: ".
Print the home.
Environment Variable Count#
a number called 'env count' is environment's count.
Print "Total environment variables: ".
Print the env count.
Iterating Environment Variables#
a text called env1 is environment's first.
Print "First env var: ".
Print the env1.
Checking if Variable Exists#
If the environment variable "DEBUG" exists then,
Print "Debug mode enabled".
Complete Example#
(A greeter using the 's property syntax)
a text called name is "World".
(Use argument if provided, otherwise use environment variable)
If arguments's count is greater than 1 then,
the name is arguments's first.
But if the environment variable "GREET_NAME" exists then,
the name is environment's "GREET_NAME".
Print "Hello, ".
Print the name.
Print "!".
(Show some environment info)
a text called user is environment's "USER".
Print "Current user: ".
Print the user.
Note: The argument and environment variable functions are only included in the binary when used, keeping programs that don't need them small and efficient.