Yorick: Shell commands

Home Manual Packages Global Index Keywords Quick Reference |
### 1.3.6 Shell commands, removing and renaming files Yorick has a `system` function which you can use to invoke operating system utilities. For example, typing `ls *.txt` to a UNIX shell will list all files in your current working directory ending with ``.txt'`. Similarly, `pwd` prints the name of your working directory:
    > system, "pwd"
    /home/icf/munro
    > system, "ls *.txt"
       damped.txt      junk.txt
This is so useful that there is a special escape syntax which automatically generates the system call, so you don't need to type the name `system` or all of the punctuation. The rule is, that if the first character of a Yorick statement is `$` (dollar), the remainder of that line becomes a quoted string which is passed to the `system` function. Hence, you really would have typed:
    > $pwd
    /home/icf/munro
    > $ls *.txt
       damped.txt      junk.txt
Note that you cannot use `;` to stack `$` escaped lines --- the semicolon will be passed to `system`. Obviously, this syntax breaks all of the ordinary rules of Yorick's grammar. On UNIX systems, the `system` function (which calls the ANSI C standard library function of the same name) usually executes your command in a Bourne shell. If you are used to a different shell, you might be surprised at some of the results. If you have some complicated shell commands for which you need, say, the C-shell `csh`, just start a copy of that shell before you issue your commands:
    > $csh
    % ls *.txt
      damped.txt    junk.txt
    % exit
    >
As this example shows, you can start up an interactive program with the `system` function. When you exit that program, you return to Yorick. One system command which you cannot use is `cd` (or `pushd` or `popd`) to change directories. The working directory of the shell you start under Yorick will change, but the change has no effect on Yorick's own working directory. Instead, use Yorick's own `cd` function:
    > cd, "new/working/directory"
    >
Also, if you write a Yorick program which manipulates temporary files, you should not use the UNIX commands `mv` or `rm` to rename or remove the files; any time you use the `system` command you are restricting your program to a particular class of operating systems. Instead, use Yorick's `rename` and `remove` functions, which will work under any operating system.