将带引号的参数传递给 REBOL 3 脚本

发布于 2024-11-24 16:07:19 字数 589 浏览 3 评论 0原文

我发现几乎不可能将带引号的参数(包含空格)传递给 REBOL 3 脚本。例如:

rebol -q script.r "foo bar" 40

如果您检查system/script/args,它包含字符串“foo bar 40”。这是没用的!信息丢失了。我需要知道 "foo bar" 是第一个参数,40 是第二个参数。如果我检查system/options/args,我会得到以下块:["foo" "bar" "40"]。再说一遍,没用!信息丢失了。

我怀疑解决这个问题的方法是使用某种参数分隔符,例如,

rebol -q script.r 'foo bar' -n 40

这可以很容易地通过 PARSE 处理,但我仍然不喜欢它。对于 system/options/args 来说,每个传递的参数包含一个字符串应该不是一件非常困难的事情。

REBOL 使用起来很愉快,这是我发现的第一个让我真正失望的东西。 :(

I've found it almost impossible to pass quoted arguments (containing spaces) to REBOL 3 scripts. For example:

rebol -q script.r "foo bar" 40

If you examine system/script/args, it contains the string "foo bar 40". This is useless! Information was lost. I need to know that "foo bar" was the first argument and 40 was the second. If I examine system/options/args, I get the following block: ["foo" "bar" "40"]. Again, useless! Information was lost.

I suspect that the solution to this is to use argument delimiters of some kind, e.g.,

rebol -q script.r 'foo bar' -n 40

This could easily be handled by PARSE, but I still don't like it. It shouldn't be terribly difficult for system/options/args to contain one string per passed argument.

REBOL's a pleasure to use, and this is the first thing I've found with which I was really disappointed. :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九公里浅绿 2024-12-01 16:07:19

在 REBOL 3 中,您观察到的行为是一个已知错误

(目前,R3 在内部将 args 作为单个字符串从操作系统传递到脚本,连接该过程中的所有原始参数。目前此过程不完全可逆,这就是此错误的原因。R3 可能应该将参数作为字符串列表,有效地保留了原始的 argv ,但删除了解释器本身使用的参数。)


在 REBOL 2 中,使用 system/options/args 更安全命令行参数,而 system/script/args 可用于更直接地在 REBOL 脚本之间传递值。我假设 R3 也会保留类似的行为。

这是一个检查参数解析行为的快速脚本:

REBOL []
print system/version
print "options args:"
probe system/options/args
print "script args:"
probe system/script/args

REBOL 2,在 OSX 上:

2.7.7.2.5
options args:
["foo bar" "40"]
script args:
"foo bar 40"

REBOL 3,在 OSX 上:

2.100.111.2.5
options args:
["foo" "bar" "40"]
script args:
"foo bar 40"

In REBOL 3, the behaviour you observe is a known bug.

(At the moment, R3 internally passes args from the OS to scripts as a single string, concatenating all original arguments in the process. Currently this process is not fully reversible, which is the cause of this bug. R3 probably should_ pass arguments as a list of strings instead, effectively preserving the original argv but stripped of arguments used by the interpreter itself.)


In REBOL 2, system/options/args is safer to use for command-line arguments, whereas system/script/args can be used to pass values between REBOL scripts more directly. I assume that similar behaviour will be kept for R3.

Here's a quick script to inspect argument parsing behaviour:

REBOL []
print system/version
print "options args:"
probe system/options/args
print "script args:"
probe system/script/args

REBOL 2, on OSX:

2.7.7.2.5
options args:
["foo bar" "40"]
script args:
"foo bar 40"

REBOL 3, on OSX:

2.100.111.2.5
options args:
["foo" "bar" "40"]
script args:
"foo bar 40"
猫性小仙女 2024-12-01 16:07:19

你可以转义引号:

rebol -q script.r \"foo bar\" 40

不知道这是shell还是REBOL的缺点?

You can escape the quotes:

rebol -q script.r \"foo bar\" 40

Don't know if this is a shortcoming of shell or REBOL?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文