Executing q in shell script

6.2k views Asked by At

I need to load a q file with a hardcoded dictionary, insert a key and assign returned value from the dictionary to an environment variable inside a shell script.

This how it would look like in q:

q)\l /home/.../marketconfig.q

q)show marketconfig[`US]

This is kind of the form I need it to be in:

CONFIG=\`q /home/.../marketconfig.q ; show marketconfig[\`US]\`

Thanks for help guys!

3

There are 3 answers

1
Manish Patel On

test.sh:

#/bin/bash
CONFIG=`q test.q`
echo config is $CONFIG

test.q:

-1 "FOO";
exit 0;

Output:

$ ./test.sh
KDB+ 2.7 2011.11.09 Copyright (C) 1993-2011 Kx Systems
l64/ ...

config is FOO

Seems to work for me. -1 prints on standard out. 0N! works too.

0
jump3r On

This is a nice way to express it as one statement without a need to alter original file or add an extra file:

CONFIG=\`q<<<'system "l marketconfig.q"; show marketconfig[\\`US]'`
0
user20349 On

In bash, you can use a heredoc:

#!/bin/bash
CONFIG=$(q /home/.../marketconfig.q << 'EOF'
show marketconfig[`US]
EOF
)