为什么Scala会忽略命令行参数中的感叹号? [英] Why does Scala ignore exclamation points in command line arguments?

查看:166
本文介绍了为什么Scala会忽略命令行参数中的感叹号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我编写的Scala脚本(或App)仅打印出命令行参数,我会注意到它会忽略所有的‘!’字符。例如,如果我的脚本如下所示:

If I write a Scala script (or App) that just prints out the command line arguments, I notice that it ignores all the '!' characters. For example, if my script looks like:

println(args(0))

然后运行:

scala MyScript "Hello!"

我得到输出:

Hello

如果我用以下命令运行它:

And if I run it with:

scala MyScript "Hello! World!"

我也得到:

Hello

这是怎么回事?的目的是什么!

What's going on? What is the purpose of the ! character in arguments that causes this behaviour?

推荐答案

是历史替换吗? 。

尝试 scala MyScript hello!退出浏览器,就像引用一样运行。

Try scala MyScript hello! with ! at EOL to see it work as if quoted.

http://www.gnu.org/software/bash/manual/bashref.html#Event-Designators

http://www.gnu.org/software/bash/ manual / bashref.html#Single-Quotes

在Windows上, scala.bat 命令脚本已启用延迟扩展。

On windows, the "scala.bat" command script has delayed expansion enabled.

http:/ /en.wikibooks.org/wiki/Windows_Batch_Scripting

http://en.wikibooks .org / wiki / Windows_Batch_Scripting#SETLOCAL

http://zh.wikibooks.org/wiki/Windows_Batch_Scripting#Command-line_arguments

禁用对<$ c $的解释c>!myvar!:

C:\Users\you> scala greeting.script "hello^!"
hello!

C:\Users\you> set world= Bob

C:\Users\you> scala greeting.script "hello!world!"
hello Bob

这篇关于为什么Scala会忽略命令行参数中的感叹号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆