Skip to content

getenv, setenv

Get or set an environment variable

getenv

Get the value of an environment variable

getenv x     getenv[x]

Where x is a symbol atom naming an environment variable, returns its value as a string. Where x is a symbol vector, returns a list of strings.

q)getenv `SHELL
"/bin/bash"
q)getenv `UNKNOWN      / returns empty if variable not defined
""

To get all the environment variables as a dictionary, use os.env from the OS module.

q)os:use`kx.os
q)type os.env[]
99h

setenv

Set the value of an environment variable

x setenv y     setenv[x;y]

Where

  • x is a symbol atom
  • y is a string

sets the environment variable named by x in the current process, and in processes it starts afterwards.

q)`RTMP setenv "/home/user/temp"
q)getenv `RTMP
"/home/user/temp"
q)\echo $RTMP
"/home/user/temp"
q)getenv `RTMP`UNKNOWN
"/home/user/temp"
""

Changing TZ with setenv takes effect immediately for gtime and ltime.


get, set

Environment