OMAKE-SHELL(1)

NAME
omake is a flexible build system designed for building a wide variety of projects. This document describes the usage and syntax of shell commands. For an overview of omake, see the omake(1) man page.

SHELL COMMANDS

Shell commands (commands to be executed by the operating system) can be freely mixed with other code.

NOTE: the syntax and shell usage is identical on all platforms, including Win32. To avoid portability problems on Win32, it is recommended that you avoid the use of the native shell interpreter cmd.

    LIB = $(dir lib)
    println(The contents of the $(LIB) directory is:)
    ls $(LIB)

  BASIC COMMANDS

The syntax of shell commands is similar to the syntax used by the Unix shell bash. In general, a command is a pipeline. A basic command is part of a pipeline. It is specified with the name of an executable and some arguments. Here are some examples.

    ls
    ls -AF .
    echo Hello world

The command is found using the current search path in the variable PATH[], which should define an array of directories containing executables.

A command may also be prefixed by environment variable definitions.

    # Prints "Hello world"
    env X="Hello world" Y=2 printenv X
    # Pass the include path to the Visual C++
    env include="c:\Program Files\Microsoft SDK\include" cl foo.cpp

  GLOBBING

Commands may contain wildcard patterns. A pattern specifies a set of files through a limited kind of regular expression. Patterns are expanded before the function is executed.

   # List all files with a .c suffix
   ls *.c
   # List all files with a single character prefix, and .c suffix
   ls ?.c
   # Rename the file hello.ml to foo.ml
   mv {hello,foo}.ml

  BACKGROUND JOBS

The command may also be placed in the background by placing an ampersand after the command. Control returns to the shell without waiting for the job to complete. The job continues to run in the background.

    gcc -o hugeprogram *.c &

  FILE REDIRECTION

Input and output can be redirected to files by using the <, >, and >& directives after the command.

    # Write to the "foo" file
    echo Hello world > foo
    # Redirect input from the foo file
    cat < foo
    # Redirect standard output and errors to the foo file
    gcc -o boo *.c >& foo

  PIPELINES

Pipelines are sequences of commands, where the output from each command is sent to the next. Pipelines are defined with the | and |& syntax. With | the output is redirected, but errors are not. With |& both output and errors are redirected.

   # Send the output of the ls command to the printer
   ls *.c | lpr
   # Send output and errors to jyh as email
   gcc -o hugefile *.c |& mail jyh

  CONDITIONAL EXECUTION

Commands may also be composed though conditional evaluation using the || and && syntax. Every command has an integer exit code, which may be zero or some other integer. A command is said to succeed if its exit code is zero. The expression command1 && command2 executes command2 only if command1 succeeds. The expression command1 || command2 executes command2 only if command1 fails.

   # Display the x/y file if possible
   cd x && cat y
   # Run foo.exe, or print an error message
   (test -x foo.exe && foo.exe) || echo "foo.exe is not executable"

  GROUPING

Parenthesis are used for grouping in a pipeline or conditional command. In the following expression, the test function is used to test whether the foo.exe file is executable. If it is, the foo.exe file is executed. If the file is not executable (or if the foo.exe command fails), the message "foo.exe is not executable" is printed.

   # Run foo.exe, or print an error message
   (test -x foo.exe && foo.exe) || echo "foo.exe is not executable"

  WHAT IS A SHELL COMMAND?

Syntactially, shell commands are any line that is not one of the following:

*   A variable definition of the form VAR=string

*   A function call f(...) or method call o.f(...)

*   A rule definition containing a colon string: ...

*   A special command, including the following:

    *   if ...

    *   switch ...

    *   match ...

    *   section ...

    *   return ...

Commands may also be builtin (aliases). See the documentation for the Shell object, defined in Pervasives for more information.

REFERENCES

  SEE ALSO

omake(1), omake-quickstart(1), omake-options(1), omake-root(1), omake-language(1), omake-shell(1), omake-rules(1), omake-base(1), omake-system(1), omake-pervasives(1), osh(1), make(1)

  VERSION

Version: 0.9.6.9 of April 11, 2006.

  LICENSE AND COPYRIGHT

(C)2003-2006, Mojave Group, Caltech

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

  AUTHOR

Jason Hickey et. al..br Caltech 256-80
Pasadena, CA 91125, USA
Email: omake-devel@metaprl.org
WWW: http://www.cs.caltech.edu/~jyh