使用变量将数据库路径传递给 \l 或 .Ql
我正在编写 aq 脚本,该脚本在特定路径中加载数据库并对其进行一些处理。数据库的位置当前在脚本中硬编码,但我想将数据库路径作为参数传递,并让它从变量中的路径加载。
目前它看起来像这样:
q) \l /path/to/dbDir #Works
我发现 .Ql 应该让我们使用变量来做到这一点,所以我尝试在脚本中使用以下内容,
dbPath:`$.z.x 0
.Q.l hsym dbPath #Fails
当使用参数 /path/to/dbDir 运行时,脚本总是失败并出现一些不可读的内容以及:
':/path/to/dbDir: No such file or directory
有人可以帮忙吗?
I'm writing a q script that loads a db in a particular path and does some processing on it. The location of the db is currently hardcoded in the script, but I want to pass the db path as an argument and get it to load from the path in the variable.
Currently it looks like this:
q) \l /path/to/dbDir #Works
I figured out that .Q.l should let us do this using a variable, so I tried using the following in the script,
dbPath:`$.z.x 0
.Q.l hsym dbPath #Fails
When running with argument /path/to/dbDir, the script always fails with some unreadable stuff and:
':/path/to/dbDir: No such file or directory
Could someone please help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
\x ...
始终等同于system"x ..."
,这是“如何将变量传递给”的一般解决方案 命令问题
\在你的情况下的
,你想要(顺便说一句,我不认为
.Ql
涉及代码的\l
,只涉及数据,所以不要尝试使用它来加载额外的 .q 文件)\x ...
is always equivalent tosystem"x ..."
, which is the general solution to the "how do i pass a variable to a\
command questionin your case, you want
(btw, i don't think
.Q.l
is involved in\l
of code, only of data, so don't try to use it to load extra .q files).Ql 与 \l 只接受一个参数,它不是 hsym,而是文件或目录 姓名。
顺便说一句,不可读的东西是函数定义,后面跟着一个类型错误(因为它不期望一个 hsym)
.Q.l is synonymous with \l which only takes a single argument, which is not an hsym but a file or directory name.
Incidentally the unreadable stuff was the function definition, followed by a type error (as it was not expecting an hsym)
好的,当我们尝试不使用 hsym 的 .Ql 时,它似乎可以工作,如下所示:
Okay, it seems to work when we try .Q.l without the hsym like this: