-
Notifications
You must be signed in to change notification settings - Fork 18
env.q
This library provides an abstraction for the raw environment variables provided via getenv
with caching and parsing of pre-defined variables.
The variables that are loaded and parsed by default are:
$QHOME
$QLIC
$PATH
- The shared object environment variable for the current Operating System (see os.q for more details)
These variables are loaded and parsed during library initialisation.
If any of the variables cached by this library are updated (via setenv
), they can be reloaded into the process by calling this function.
The cache configuration is found at .env.cfg.vars
.
q) .env.loadAllEnvVars[]
2021.01.10 16:37:45.306 INFO pid-1171 jas 0 Loading all configured environment variables [ Total: 4 ]
2021.01.10 16:37:45.306 DEBUG pid-1171 jas 0 Loading environment variable [ Variable: QHOME ] [ Parse Function: .convert.stringToHsym ]
2021.01.10 16:37:45.306 DEBUG pid-1171 jas 0 Loading environment variable [ Variable: QLIC ] [ Parse Function: .convert.stringToHsym ]
2021.01.10 16:37:45.306 DEBUG pid-1171 jas 0 Loading environment variable [ Variable: PATH ] [ Parse Function: .env.i.parsePathTypeVar ]
2021.01.10 16:37:45.329 DEBUG pid-1171 jas 0 Loading environment variable [ Variable: LD_LIBRARY_PATH ] [ Parse Function: .env.i.parsePathTypeVar ]
Queries the specified environment varaible either from the cache or directly via getenv
if not pre-configured.
This function will throw an EnvironmentVariableNotDefinedException
if the specified environment variable is not cached and getenv
returns empty string.
/ Cached variable (folder path)
q) .env.get`QHOME
`:/opt/q/current
/ Cached variable (PATH-type environment variable)
q) .env.get`PATH
`:/home/jas/.local/bin`:/usr/local/sbin`:/usr/local/bin`:/usr/sbin`:/usr/bin`..
/ Un-cached, set variable
q) .env.get`EDITOR
"vim"
/ Un-cached, empty variable
q) .env.get`LD_PRELOAD
'EnvironmentVariableNotDefinedException
[0] .env.get`LD_PRELOAD
Searches for the specified command in the $PATH
environment variable and returns the first match. This provides equivalent functionality to the Linux which
command.
q).env.which`ls
`:/bin/ls
q)system "which ls"
"/bin/ls"
/ Exception if command not found
q).env.which`something
'CommandNotFoundException
[0] .env.which `something
^
q)system "which something"
'os
[1] \which something
Copyright (C) Sport Trades Ltd 2017 - 2020, John Keys and Jaskirat Rajasansir 2020 - 2024