4

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!

chrisaycock
  • 36,470
  • 14
  • 88
  • 125
jump3r
  • 161
  • 1
  • 7

3 Answers3

1

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.

Manish Patel
  • 4,411
  • 4
  • 25
  • 48
1

In bash, you can use a heredoc:

#!/bin/bash
CONFIG=$(q /home/.../marketconfig.q << 'EOF'
show marketconfig[`US]
EOF
)
user20349
  • 509
  • 2
  • 9
0

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]'`
jump3r
  • 161
  • 1
  • 7