shQuote                 package:base                 R Documentation

_Q_u_o_t_e _S_t_r_i_n_g_s _f_o_r _U_s_e _i_n _O_S _S_h_e_l_l_s

_D_e_s_c_r_i_p_t_i_o_n:

     Quote a string to be passed to an operating system shell.

_U_s_a_g_e:

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

_A_r_g_u_m_e_n_t_s:

  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.

_D_e_t_a_i_l_s:

     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'.

     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.

_R_e_f_e_r_e_n_c_e_s:

     Loukides, M. et al (2002) _Unix Power Tools_ Third Edition. 
     O'Reilly.  Section 27.12.

     <URL: http://www.mhuffman.com/notes/dos/bash_cmd.htm>

_S_e_e _A_l_s_o:

     'Quotes' for quoting R code.

     'sQuote' for quoting English text.

_E_x_a_m_p_l_e_s:

     test <- "abc$def`gh`i\\j"
     cat(shQuote(test), "\n")
     ## Not run: system(paste("echo", shQuote(test)))
     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)))
     cat(shQuote(tryit, type="csh"), "\n")

     ## Windows-only example.
     perlcmd <- 'print "Hello World\n";'
     ## Not run: shell(paste("perl -e", shQuote(perlcmd, type="cmd")))

