Hi all
I am trying to pass environment variable to Q in my script, say
export abc=def
q q_script.q
Then in q_script.q, I do
env:getenv `abc
However, env is null but not “def”, what is the problem? Or, if there any other way to pass parameter to Q
Regards,
Carfield
Hi Carfield,
I am able to set the environment variable and it appears correctly when I call my script as follows (q_script contains only - env:getenv `abc ) :
~$ export abc=def
~$ q q_script.q
KDB+ 3.5 2017.08.22 Copyright (C) 1993-2017 Kx Systems
l64/ 8()core 16048MB redens homer.aquaq.co.uk 127.0.1.1 EXPIRE 2018.06.30 AquaQ #50170
q)env
“def”
q)
However this environment variable is not set permanently. If you close the terminal and start another, you will have to export the variable again before running the script or you will get “”:
redens@homer:~$ q q_script.q
KDB+ 3.5 2017.08.22 Copyright (C) 1993-2017 Kx Systems
l64/ 8()core 16048MB redens homer.aquaq.co.uk 127.0.1.1 EXPIRE 2018.06.30 AquaQ #50170
q)env
“”
q)
To make this variable permanent you could add export abc=de f into your .bashrc (or equivalent). Anytime you run the script now the variable will be available.
####NEW TERMINAL####
redens@homer:~$ q q_script.q
KDB+ 3.5 2017.08.22 Copyright (C) 1993-2017 Kx Systems
l64/ 8()core 16048MB redens homer.aquaq.co.uk 127.0.1.1 EXPIRE 2018.06.30 AquaQ #50170
q)
q)
q)env
“def”
Could this have been the issue or were you unable to pass the parameter even after exporting the variable prior to running your script?
Hope this helps,
Ross
Just to add you could also use setenv at the beginning of your q script to set the variable when the script is loaded i.e.
`abc setenv “def”
env:getenv `abc
Just note that this will only be available in the q session.
redens@homer:~$ env | grep abc
redens@homer:~$
redens@homer:~$
redens@homer:~$ q q_script.q
KDB+ 3.5 2017.08.22 Copyright (C) 1993-2017 Kx Systems
l64/ 8()core 16048MB redens homer.aquaq.co.uk 127.0.1.1 EXPIRE 2018.06.30 AquaQ #50170
q)
q)
q)env
“def”
q)
q)\
~$ env | grep abc
~$
Flying1
January 11, 2018, 11:05am
4
As Ross mentioned, your script should work, given that both export and q commands were executed from the same shell.
In order to pass environment variables only to the q process, you could alternatively do this:
env abc=def q q_script.q
Thanks all, yes that is working, just somehow some other problem resetting the variable