shQuote
Quote Strings for Use in OS Shells
Description
Usage
shQuote(string, type = c("sh", "csh", "cmd"))
Arguments
string |
a vector of character strings.
|
type |
the operating system shell type. Can be "sh",
"csh" or "cmd". If this value is missing and the
operating system is Windows, it is set to "cmd".
|
Details
- If type is "cmd", then "\"" is added at
the beginning and ending of string, and "\"" is
replaced with "\"\"" by regular-expression matching.
- If type is "sh" or "csh", and if length(string)==0,
then the empty string "" is returned.
- If type is "sh" or "csh", and if string
contains no character "'", then "'" is added at the
begining and ending of string.
- If type is "sh", special
characters "\"$`\\" are escaped by adding "\\" in front of them
and then "\"" is added at the beginning and end.
- If type is "csh", and if string does not
contain special characters "$`", escape characters "!\\" by adding "\\"
in front of them and then "\"" is added at the beginning and end.
- If type is "csh", and if string does
contain special characters "$`", replace characters "'" with "'\"'\"'"
and then "'" is added at the beginning and end.
Value
returns the quoted string.
Examples
shQuote(getwd())
shQuote('foo/bar.txt', type="sh")
# [1] "'foo/bar.txt'"
shQuote('foo\bar.txt', type="cmd")
# [1] "\"foo\bar.txt\""