unix(command, input=NULL, output=T) unix.shell(cmd, shell = "/bin/sh", ...) !cmd .System(cmd)
command
.
If
input
is missing, nothing special is done to provide input to
the command.
TRUE
, the standard output of the
shell command will be returned as a character vector,
with each line of output turned into one element of the vector.
If
FALSE
, standard output for the command remains unchanged; typically,
it is directed to the user's terminal.
cmd
.
unix
function.
command
if
output
is
TRUE
.
Otherwise, a numeric value giving the exit status of
command
;
an exit status of
0
means successful execution of
command
.
output=FALSE
.
Use
output=FALSE
when the executed
command
interacts with the user.
unix.shell
provides the same features as the
unix
function with
the addition that you may specify a
shell
to use instead of the
Bourne shell. The default shell to use is the Bourne shell.
Restriction: The shell you select must allow a file as argument and
must interpret the commands contained in such a file.
Use an exclamation mark (
!
) as the first character of a command line
to escape to a shell. For
!
escapes, S-PLUS uses the shell named by
the environment variable
S_SHELL
.
S_SHELL
defaults to the value
of environment variable
SHELL
, if set, or if not set, the Bourne
shell. The shell selected by
S_SHELL
is subject to the same
restrictions as apply for
unix.shell
(see above). Warning: since
S_SHELL
depends on
SHELL
by default, if you have a
SHELL
which does not meet the restrictions, shell escapes might fail, in
which case you should set
S_SHELL
to the Bourne or C shell.
.System
is used internally by ! escapes; it is not intended to be
used directly.
# create a character vector from the contents of a file, # one element of the vector per line of the file unix("cat myfile") unix("cat myfile",output=F) # same as !cat myfile unix("more", c("line 1", "here is line 2", "and line 3"), F) # C shell commands will work if S_SHELL is set to "/bin/csh" # (You can set S_SHELL explicitly, or let it default to SHELL or /bin/sh) !alias # works if S_SHELL is /bin/csh # You can use unix.shell in place of unix to run csh commands unix.shell(command = "alias", shell = "/bin/csh", out=F) # You can make a convenient function to run csh commands "csh"<- function(cmd, ...) { unix.shell(command = cmd, shell = "/bin/csh", ...) }