Next: showplot() Up: MacAnova Help File Previous: setseeds()   Contents


shell(command), shell(command,keep:T) or shell(command,interact:T),
  command a quoted string or CHARACTER scalar.
!command immediately after the prompt

Keywords: control, general
shell(command) submits the CHARACTER vector or string command to the
operating system for execution.  It is implemented in the Unix/Linux,
Motif, and DOS versions but not on the Macintosh.  It does not work in
Windows 3.1 or Windows 95 but may in Windows NT.  Except in the limited
memory DOS version (BCPP), the program run by command must not expect
any input from the keyboard.

For example, in the Unix/Linux or Motif versions,
  Cmd> shell("ls -l *.dat")
causes the output from the Unix/Linux command 'ls -l *.dat' to be
printed, giving a full listing of all files in the current directory
with names ending with '.dat'.  Under DOS, the same effect is obtained
  Cmd> shell("dir *.dat").

shell(command, interact:T) does the same as shell(command) except that
you can interact with the program that is started up.  This option is
required if, for example, you are using shell() to run an editor to
modify a file.  In the limited memory DOS version (BCPP), you can always
interact with the command.  When in doubt as to whether a program
expects keyboard input, use interact:T.

shell(command, keep:T) runs the command in non-interactive mode and
returns its output as a CHARACTER vector, with each line of output an
element.  The command must not expect any input from the keyboard.  This
is not implemented in the limited memory DOS version (BCPP).

Example on Unix/Linux:
  Cmd> datafiles <-\
        shell(paste("cd ",DATAPATHS[1],"; ls *.dat"), keep:T)
returns a vector of file names of the form *.dat in the directory whose
name is in DATAPATHS[1].  See topic 'DATAPATHS'.

                        Operating System Escapes
Somewhat simpler, but less powerful because it cannot be included in a
macro, is the use of the 'escape' character '!'.  In the Unix/Linux,
Motif and DOS versions, any line of input starting with '!' immediately
after the prompt will be passed on to the operating system for execution
(without the '!').  Specifically,
  Cmd> !command to be run ...
is equivalent to
  Cmd> shell("command to be run ...", interact:T).
For example,
  Cmd> !ls -l *.dat
  Cmd> shell("ls -l *.dat", interact:T)
are equivalent.

In a command line starting with '!', double quotes ('"') and curly
brackets ('{' and '}') have no special significance.  The only "special"
character is a backslash ('\') and then only when it occurs at the end
of line to indicate that the command is continued on the next line.
Unlike the case when an ordinary line is continued with backslash, a
trailing backslash is deleted and is not seen by the operating system.
Unbalanced quotes or brackets are ignored.

Under DOS, but not Unix/Linux, you can change default directories by,
for example,
  Cmd> !cd b:\data   # or shell("cd b:\\data")

Caution: If you want to execute in MacAnova a command that starts with
'!'  (for example !(x < y)), precede it with a space.  For example,
  Cmd> !(x < y)
attempts to execute "(x < y)" as a shell command, probably causing an
error, while
  Cmd>  !(x < y) #note the extra space
is computed in MacAnova.  Conversely,
  Cmd>  !ls -l *.dat
is an error, because a space has been typed before '!'.

In the DOS extended memory version (DJGPP), shell(command) or
shell(command, keep:T) sometimes hangs.  shell(command,interact:T) or
!command is more reliable.

In the Windows version, shell(command,interact:T) and !command ignores
command and starts up DOS similar to selecting MS-DOS Prompt in the
Program Manager window.

In the Motif version, shell(command,interact:T) and !command can be
confusing: Output does not appear in the MacAnova command window, but in
the "parent" window from which MacAnova was started up, and any input
must be typed in parent window.

On a Macintosh, starting a line with '!' is an error.

Gary Oehlert 2003-01-15