找回密码
 注册
查看: 2138|回复: 0

R语言:shQuote()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-17 09:42:26 | 显示全部楼层 |阅读模式
shQuote(base)
shQuote()所属R语言包:base

                                        Quote Strings for Use in OS Shells
                                         引述操作系统壳使用字符串

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

Quote a string to be passed to an operating system shell.
举一个字符串被传递到操作系统外壳。


用法----------Usage----------


shQuote(string, type = c("sh", "csh", "cmd"))



参数----------Arguments----------

参数:string
a character vector, usually of length one.
一个字符向量,通常长度为一。


参数:type
character: the type of shell.  Partial matching is supported.  "cmd" refers to the Windows NT shell, and is the default under Windows.
特点:壳式。部分匹配支持。 "cmd"是指Windows NT外壳,是Windows下的默认。


Details

详情----------Details----------

The default type of quoting supported under Unix-alikes is that for the Bourne shell sh.  If the string does not contain single quotes, we can just surround it with single quotes.  Otherwise, the string is surrounded in double quotes, which suppresses all special meanings of metacharacters except dollar, backquote and backslash, so these (and of course double quote) are preceded by backslash.  This type of quoting is also appropriate for bash, ksh and zsh.
在Unix下相似者支持的默认引用类型是Bourne shell的sh。如果字符串不包含单引号,我们可以只用单引号包围它。反引号和反斜杠,否则,双引号包围的字符串,从而抑制除美元元字符的所有特殊意义,所以这些(当然双引号)之前反斜杠。这种类型的引用也是适当bash,ksh和zsh。

The other type of quoting is for the C-shell (csh and tcsh).  Once again, if the string does not contain single quotes, we can just surround it with single quotes.  If it does contain single quotes, we can use double quotes provided it does not contain dollar or backquote (and we need to escape backslash, exclamation mark and double quote).  As a last resort, we need to split the string into pieces not containing single quotes and surround each with single quotes, and the single quotes with double quotes.
引用其他类型的C-shell(csh和tcsh)。再次,如果该字符串不包含单引号,我们可以只用单引号包围它。如果它包含单引号,我们可以使用双引号,只要它不包含美元或反引号(我们需要摆脱反斜杠,感叹号和双引号)。作为最后的手段,我们需要分割成块不包含单引号的字符串和环绕每个单引号,单引号与双引号。

The Windows shell supports only double quoting.  All this implementation does is to surround the string by double quotes and escape internal double quotes by a backslash.  As Windows path names cannot contain double quotes, this makes shQuote safe for use with file paths in system, and with shell if the default shell is used.
Windows外壳程序只支持双引号。这一切实现并不由双引号包围的字符串和逃避内部双引号,反斜线。由于Windows路径名称不能包含双引号,这使得shQuote安全使用文件路径system,用shell如果使用默认的shell。

It will usually be safe to use shQuote to quote arguments of a command, but because system does not use a shell, interpretation of quoted arguments is done by the run-time code of the executable.  This may depend on the compiler used: Microsoft's rules for the C run-time are given at http://msdn2.microsoft.com/en-us/library/ms880421.aspx.
使用shQuote引用命令的参数,它通常是安全的,但因为system不使用shell,引用参数的解释是通过运行时代码的可执行文件。这可能取决于所使用的编译器:微软的C运行时规则http://msdn2.microsoft.com/en-us/library/ms880421.aspx。


参考文献----------References----------

Unix Power Tools Third Edition.  O'Reilly.  Section 27.12.


参见----------See Also----------

Quotes for quoting R code.
Quotes引述R代码。

sQuote for quoting English text.
sQuote引述英文文本。


举例----------Examples----------


test <- "abc$def`gh`i\\j"
cat(shQuote(test), "\n")
## Not run: system(paste("echo", shQuote(test)))[#无法运行系统(膏(“回声”,shQuote(测试)))]
test <- "don't do it!"
cat(shQuote(test), "\n")

tryit <- paste("use the", sQuote("-c"), "switch\nlike this")
cat(shQuote(tryit), "\n")
## Not run: system(paste("echo", shQuote(tryit)))[#无法运行系统(膏(“回声”,shQuote(tryit)))]
cat(shQuote(tryit, type="csh"), "\n")

## Windows-only example.[#Windows的唯一的例子。]
perlcmd <- 'print "Hello World\n";'
## Not run: shell(paste("perl -e", shQuote(perlcmd, type="cmd")))[#无法运行:壳牌(膏(“的perl-e”的,shQuote(perlcmd,键入“CMD”)))]

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-23 06:18 , Processed in 0.021097 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表