jump3r
jump3r

Reputation: 161

Executing q in shell script

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!

Upvotes: 4

Views: 6396

Answers (3)

jump3r
jump3r

Reputation: 161

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]'`

Upvotes: 0

Darren
Darren

Reputation: 549

In bash, you can use a heredoc:

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

Upvotes: 1

Manish Patel
Manish Patel

Reputation: 4491

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.

Upvotes: 1

Related Questions