shQuote                package:utils                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.

_D_e_t_a_i_l_s:

     The default type of quoting supported 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 'ksh' and 'bash'.

     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.

     The Windows shell supports only double quoting.  All this
     implementation does is to surround by double quotes and escape
     internal double quotes by a backslash.

_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:

     'sQuote' for quoting in 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 <- "use the `-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")))

